1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
5 struct A
; // expected-note 4 {{forward declaration of 'A'}}
7 struct Abstract
{ virtual void f() = 0; }; // expected-note {{unimplemented pure virtual method 'f'}}
12 } catch(int i
) { // expected-note {{previous definition}}
14 int i
; // expected-error {{redefinition of 'i'}}
16 } catch(void v
) { // expected-error {{cannot catch incomplete type 'void'}}
17 } catch(A a
) { // expected-error {{cannot catch incomplete type 'A'}}
18 } catch(A
*a
) { // expected-error {{cannot catch pointer to incomplete type 'A'}}
19 } catch(A
&a
) { // expected-error {{cannot catch reference to incomplete type 'A'}}
20 } catch(Abstract
) { // expected-error {{variable type 'Abstract' is an abstract class}}
26 int j
= i
; // expected-error {{use of undeclared identifier 'i'}}
30 } catch(...) { // expected-error {{catch-all handler must come last}}
38 throw throw; // expected-error {{cannot throw object of incomplete type 'void'}}
39 throw (A
*)0; // expected-error {{cannot throw pointer to object of incomplete type 'A'}}
45 goto l4
; // expected-error {{cannot jump}}
46 goto l3
; // expected-error {{cannot jump}}
47 goto l2
; // expected-error {{cannot jump}}
49 try { // expected-note 4 {{jump bypasses initialization of try block}}
52 goto l4
; // expected-error {{cannot jump}}
53 goto l3
; // expected-error {{cannot jump}}
56 } catch(int) { // expected-note 4 {{jump bypasses initialization of catch block}}
59 goto l4
; // expected-error {{cannot jump}}
61 goto l2
; // expected-error {{cannot jump}}
63 } catch(...) { // expected-note 4 {{jump bypasses initialization of catch block}}
67 goto l3
; // expected-error {{cannot jump}}
68 goto l2
; // expected-error {{cannot jump}}
73 goto l4
; // expected-error {{cannot jump}}
74 goto l3
; // expected-error {{cannot jump}}
75 goto l2
; // expected-error {{cannot jump}}
87 return; // expected-error {{return in the catch of a function try block of a constructor is illegal}}
94 BadReturn::BadReturn(int) try {
99 return; // expected-error {{return in the catch of a function try block of a constructor is illegal}}
103 return; // expected-error {{return in the catch of a function try block of a constructor is illegal}}
108 // Cannot throw an abstract type.
113 throw *this; // expected-error{{cannot throw an object of abstract type 'foo'}}
115 virtual void test () = 0; // expected-note{{unimplemented pure virtual method 'test'}}
119 namespace NA
{ struct S
; }
120 namespace NB
{ struct S
; }
133 void f() throw (A
[10]);
136 template<typename T
> struct B
{
137 void f() throw (B
[10]);
139 template struct B
<int>;
141 void f() throw (int[10], int(*)());
142 void f() throw (int*, int());
144 template<typename T
> struct C
{
146 #if __cplusplus <= 199711L
147 // expected-error@-2 {{pointer to incomplete type 'Decay::E' is not allowed in exception specification}}
154 #if __cplusplus <= 199711L
155 // expected-note@-2 {{forward declaration of 'Decay::E'}}
159 #if __cplusplus <= 199711L
160 // expected-note@-2 {{in instantiation of template class 'Decay::C<Decay::E[10]>' requested here}}
164 void rval_ref() throw (int &&); // expected-error {{rvalue reference type 'int &&' is not allowed in exception specification}}
165 #if __cplusplus <= 199711L
166 // expected-warning@-2 {{rvalue references are a C++11 extension}}
169 namespace HandlerInversion
{
176 } catch (B
&b
) { // expected-note {{for type 'HandlerInversion::B &'}}
177 } catch (D
&d
) { // expected-warning {{exception of type 'HandlerInversion::D &' will be caught by earlier handler}}
183 } catch (B
*b
) { // expected-note {{for type 'HandlerInversion::B *'}}
184 } catch (D
*d
) { // expected-warning {{exception of type 'HandlerInversion::D *' will be caught by earlier handler}}
190 } catch (D
&d
) { // Ok
197 } catch (B
&b
) { // Ok
210 } catch (B
&b
) { // expected-note {{for type 'HandlerInversion::B &'}}
211 } catch (D2
&d
) { // expected-warning {{exception of type 'HandlerInversion::D2 &' will be caught by earlier handler}}
217 } catch (B
*b
) { // Ok
218 } catch (D
&d
) { // Ok
222 } catch (B b
) { // Ok
223 } catch (D
*d
) { // Ok
229 } catch (const B
&b
) { // expected-note {{for type 'const HandlerInversion::B &'}}
230 } catch (D2
&d
) { // expected-warning {{exception of type 'HandlerInversion::D2 &' will be caught by earlier handler}}
234 } catch (B
&b
) { // expected-note {{for type 'HandlerInversion::B &'}}
235 } catch (const D2
&d
) { // expected-warning {{exception of type 'const HandlerInversion::D2 &' will be caught by earlier handler}}
239 } catch (B b
) { // expected-note {{for type 'HandlerInversion::B'}}
240 } catch (D
&d
) { // expected-warning {{exception of type 'HandlerInversion::D &' will be caught by earlier handler}}
245 namespace ConstVolatileThrow
{
247 S() {} // expected-note{{candidate constructor not viable}}
248 S(const S
&s
); // expected-note{{candidate constructor not viable}}
251 typedef const volatile S CVS
;
254 throw CVS(); // expected-error{{no matching constructor for initialization}}
258 namespace ConstVolatileCatch
{
261 S(const volatile S
&s
);
264 S(const S
&s
); // expected-note {{declared private here}}
272 } catch (volatile S s
) { // expected-error {{calling a private constructor}}
280 } catch (int(*)[i
]) { // expected-error{{cannot catch variably modified type}}
286 } catch (int(*)[i
]) { // expected-error{{cannot catch variably modified type}}