1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,precxx17 %std_cxx98-14 %s
2 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %std_cxx17- %s
4 struct A
; // expected-note 4 {{forward declaration of 'A'}}
6 struct Abstract
{ virtual void f() = 0; }; // expected-note {{unimplemented pure virtual method 'f'}}
11 } catch(int i
) { // expected-note {{previous definition}}
13 int i
; // expected-error {{redefinition of 'i'}}
15 } catch(void v
) { // expected-error {{cannot catch incomplete type 'void'}}
16 } catch(A a
) { // expected-error {{cannot catch incomplete type 'A'}}
17 } catch(A
*a
) { // expected-error {{cannot catch pointer to incomplete type 'A'}}
18 } catch(A
&a
) { // expected-error {{cannot catch reference to incomplete type 'A'}}
19 } catch(Abstract
) { // expected-error {{variable type 'Abstract' is an abstract class}}
25 int j
= i
; // expected-error {{use of undeclared identifier 'i'}}
29 } catch(...) { // expected-error {{catch-all handler must come last}}
37 throw throw; // expected-error {{cannot throw object of incomplete type 'void'}}
38 throw (A
*)0; // expected-error {{cannot throw pointer to object of incomplete type 'A'}}
44 goto l4
; // expected-error {{cannot jump}}
45 goto l3
; // expected-error {{cannot jump}}
46 goto l2
; // expected-error {{cannot jump}}
48 try { // expected-note 4 {{jump bypasses initialization of try block}}
51 goto l4
; // expected-error {{cannot jump}}
52 goto l3
; // expected-error {{cannot jump}}
55 } catch(int) { // expected-note 4 {{jump bypasses initialization of catch block}}
58 goto l4
; // expected-error {{cannot jump}}
60 goto l2
; // expected-error {{cannot jump}}
62 } catch(...) { // expected-note 4 {{jump bypasses initialization of catch block}}
66 goto l3
; // expected-error {{cannot jump}}
67 goto l2
; // expected-error {{cannot jump}}
72 goto l4
; // expected-error {{cannot jump}}
73 goto l3
; // expected-error {{cannot jump}}
74 goto l2
; // expected-error {{cannot jump}}
86 return; // expected-error {{return in the catch of a function try block of a constructor is illegal}}
93 BadReturn::BadReturn(int) try {
98 return; // expected-error {{return in the catch of a function try block of a constructor is illegal}}
102 return; // expected-error {{return in the catch of a function try block of a constructor is illegal}}
107 // Cannot throw an abstract type.
112 throw *this; // expected-error{{cannot throw an object of abstract type 'foo'}}
114 virtual void test () = 0; // expected-note{{unimplemented pure virtual method 'test'}}
118 namespace NA
{ struct S
; }
119 namespace NB
{ struct S
; }
130 #if __cplusplus < 201703L
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}}
170 namespace HandlerInversion
{
177 } catch (B
&b
) { // expected-note {{for type 'B &'}}
178 } catch (D
&d
) { // expected-warning {{exception of type 'D &' will be caught by earlier handler}}
184 } catch (B
*b
) { // expected-note {{for type 'B *'}}
185 } catch (D
*d
) { // expected-warning {{exception of type 'D *' will be caught by earlier handler}}
191 } catch (D
&d
) { // Ok
198 } catch (B
&b
) { // Ok
211 } catch (B
&b
) { // expected-note {{for type 'B &'}}
212 } catch (D2
&d
) { // expected-warning {{exception of type 'D2 &' will be caught by earlier handler}}
218 } catch (B
*b
) { // Ok
219 } catch (D
&d
) { // Ok
223 } catch (B b
) { // Ok
224 } catch (D
*d
) { // Ok
230 } catch (const B
&b
) { // expected-note {{for type 'const B &'}}
231 } catch (D2
&d
) { // expected-warning {{exception of type 'D2 &' will be caught by earlier handler}}
235 } catch (B
&b
) { // expected-note {{for type 'B &'}}
236 } catch (const D2
&d
) { // expected-warning {{exception of type 'const D2 &' will be caught by earlier handler}}
240 } catch (B b
) { // expected-note {{for type 'B'}}
241 } catch (D
&d
) { // expected-warning {{exception of type 'D &' will be caught by earlier handler}}
246 namespace ConstVolatileThrow
{
248 S() {} // precxx17-note{{candidate constructor not viable}}
249 S(const S
&s
); // precxx17-note{{candidate constructor not viable}}
252 typedef const volatile S CVS
;
255 throw CVS(); // precxx17-error{{no matching constructor for initialization}}
259 namespace ConstVolatileCatch
{
262 S(const volatile S
&s
);
265 S(const S
&s
); // expected-note {{declared private here}}
273 } catch (volatile S s
) { // expected-error {{calling a private constructor}}
279 void test1(int i
) { // expected-note {{declared here}}
281 } catch (int(*)[i
]) { // expected-error{{cannot catch variably modified type}} \
282 expected
-warning
{{variable length arrays in C
++ are a Clang extension
}} \
283 expected
-note
{{function parameter
'i' with unknown value cannot be used in a constant expression
}}
287 int i
; // expected-note {{declared here}}
289 } catch (int(*)[i
]) { // expected-error{{cannot catch variably modified type}} \
290 expected
-warning
{{variable length arrays in C
++ are a Clang extension
}} \
291 expected
-note
{{read of non
-const variable
'i' is
not allowed in a constant expression
}}