1 // { dg-do assemble { target c++14_down } }
2 // { dg-additional-options "-Wno-deprecated" }
3
4 // Copyright (C) 1999 Free Software Foundation, Inc.
5 // Contributed by Nathan Sidwell 19 Jan 1999 <nathan@acm.org>
6
7 // Determine that throw specifiers are checked correctly.
8
9 // [except.spec] 1, a type in an exception specifier shall not be incomplete,
10 // or pointer or ref to incomplete
11 struct X; // { dg-message "" } forward declaration.*
12 void fn1() throw(X); // { dg-error "" } invalid use of undefined type
13 void fn2() throw(X *); // { dg-error "" } invalid use of undefined type
14 void fn3() throw(X &); // { dg-error "" } invalid use of undefined tyoe
15 void fn4() throw(void); // { dg-error "" } invalid use of void expression
16 void fn5() throw(void &); // { dg-error "" } invalid type // ERROR - invalid use of void
17 // except for cv pointer to void
18 void fn6() throw(void *); // ok -- pointer to void
19 void fn7() throw(void const *); // ok -- pointer to cv void
20
21 template<class T> void fny() throw(T); // ok (so far)
22 template<> void fny<int>() throw(int); // ok
23 template<> void fny<void>() throw(void); // { dg-error "" } invalid use of void
24
fnx(T *)25 template<class T> void fnx(T *) throw(T){} // { dg-error "" } invalid use of void expression
fx()26 void fx()
27 {
28 fnx((int *)0);
29 fnx((void *)0); // { dg-message "required from here" }
30 }
31
32 // [except.spec] 2, exception specifiers must be the same set of types (but
33 // can be reordered)
34 void baz1() throw(int, char);
baz1()35 void baz1() throw(char, int){} // reordering is ok
36
37 void baz2() throw(int, char);
baz2()38 void baz2() throw(int, char, int){} // duplicates are ignored
39
40 typedef int Int;
41 void baz3() throw(int, char);
baz3()42 void baz3() throw(Int, char){} // typedefs are the same type ...
43
44 void baz4() throw(int, Int, char); // ... so this is a duplicate
baz4()45 void baz4() throw(Int, char){}
46
47 void fna() throw(int, char); // { dg-message "" } to previous declaration
48 void fna() throw(int const, char); // { dg-error "" } declaration different exceptions // ERROR - to previous declaration
fna()49 void fna() throw(int){} // { dg-error "" } declaration different exceptions
50
51 void fnb() throw(int, char); // { dg-message "" } to previous declaration
fnb()52 void fnb() throw(char){} // { dg-error "" } declaration different exceptions
53
54 void fnc() throw(int, char); // { dg-message "" } to previous declaration
fnc()55 void fnc() throw(char, int, float){} // { dg-error "" } declaration different exceptions
56
57 void fnd() throw(); // { dg-message "" } to previous declaration
fnd()58 void fnd() throw(char){} // { dg-error "" } declaration different exceptions
59
60 void fne() throw(char); // { dg-message "" } to previous declaration
fne()61 void fne() throw(){} // { dg-error "" } declaration different exceptions
62
63 void fnf(); // { dg-message "" } to previous declaration
fnf()64 void fnf() throw(char){} // { dg-error "" } declaration different exceptions
65
66 void fng() throw(char); // { dg-message "" } to previous declaration
fng()67 void fng(){} // { dg-error "" } declaration different exceptions
68
69 void fnh() throw(int, char); // { dg-message "" } to previous declaration
fnh()70 void fnh() throw(int, float){} // { dg-error "" } declaration different exceptions
71
72 void fni() throw(int, char); // { dg-message "" } to previous declaration
fni()73 void fni() throw(float, char){} // { dg-error "" } declaration different exceptions
74
75 // [except.spec] 3, virtual function overriders shall throw a subset of the
76 // overridden function
77 struct E {};
78 struct F : public E {};
79 struct F1 : public E {};
80 struct G : public F, F1 {};
81 struct H : private E {};
82 struct A
83 {
84 virtual void foo() throw(); // { dg-message "" } overridden
85 virtual void baz() throw(double, int);
86 virtual void bar();
87 virtual void qux() throw(E);
88 virtual void qux(int) throw(E const *); // { dg-message "" } overridden (pedantically)
89 virtual void quux() throw(F); // { dg-message "" } overridden
90 virtual void quux(int) throw(F *); // { dg-message "" } overridden
91 virtual void wibble() throw(E); // { dg-message "" } overridden
92 virtual void wobble() throw(E *); // { dg-message "" } overridden
93 virtual void wobble(int) throw(E *); // { dg-message "" } overridden
94 virtual void wabble(int) throw(E *);
95 virtual void wubble(int) throw(E *, H *);
96 virtual ~A() throw(); // { dg-message "" } overriding
97 };
98
99 struct B : A
100 {
101 virtual void foo() throw(int); // { dg-error "" } looser throw - A::foo
102 virtual void baz() throw(double); // ok subset
103 virtual void bar(int) throw(int); // ok not overriding
104 virtual void qux() throw(F); // ok subset
105 virtual void qux(int) throw(F *); // { dg-error "" } looser (pedantically)
106 virtual void quux() throw(E); // { dg-error "" } looser throw - A::quux()
107 virtual void quux(int) throw(E *); // { dg-error "" } looser throw - A::quux(int)
108 virtual void wibble() throw(E *); // { dg-error "" } looser throw - A::wibble
109 virtual void wobble() throw(G *); // { dg-error "" } looser throw - A::wobble()
110 virtual void wobble(int) throw(H *); // { dg-error "" } looser throw - A::wobble(int)
111 virtual void wubble(int) throw(H *); // ok
112 virtual void wabble(int) throw(F1 *, F *); // ok
113 };
114
115 struct A1
116 {
117 virtual void foo() throw(int);
118 virtual void bar() throw(); // { dg-message "" } overridden
119 virtual ~A1() throw(int);
120 };
121
122 struct B1 : A
123 {
124 };
125
126 struct C : A, A1 // { dg-error "" } looser throw - A::~A()
127 {
128 virtual void foo() throw(int); // { dg-error "" } looser throw - A::foo
129 virtual void bar() throw(int); // { dg-error "" } looser throw - A1::bar
130 };
131
132 struct D : A, A1
133 {
134 virtual ~D() throw(int); // { dg-error "" } looser throw - A::~A()
135 };
136
137 // [except.spec] 5, types shall not be defined in exception specifiers
138 void fn8() throw(struct Z {}); // { dg-error "" } ANSI C++ forbids
139