3 // Copyright (C) 1999 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 19 Jan 1999 <nathan@acm.org>
6 // Determine that throw specifiers are checked correctly.
8 // [except.spec] 1, a type in an exception specifier shall not be incomplete,
9 // or pointer or ref to incomplete
10 struct X; // { dg-error "" } forward declaration.*
11 void fn1() throw(X); // { dg-error "" } invalid use of undefined type
12 void fn2() throw(X *); // { dg-error "" } invalid use of undefined type
13 void fn3() throw(X &); // { dg-error "" } invalid use of undefined tyoe
14 void fn4() throw(void); // { dg-error "" } invalid use of void expression
15 void fn5() throw(void &); // { dg-error "" } invalid type // ERROR - invalid use of void
16 // except for cv pointer to void
17 void fn6() throw(void *); // ok -- pointer to void
18 void fn7() throw(void const *); // ok -- pointer to cv void
20 template<class T> void fny() throw(T); // ok (so far)
21 template<> void fny<int>() throw(int); // ok
22 template<> void fny<void>() throw(void); // { dg-error "" } invalid use of void
24 template<class T> void fnx(T *) throw(T){} // { dg-error "" } invalid use of void expression
28 fnx((void *)0); // { dg-error "" } instantiated from here
31 // [except.spec] 2, exception specifiers must be the same set of types (but
33 void baz1() throw(int, char);
34 void baz1() throw(char, int){} // reordering is ok
36 void baz2() throw(int, char);
37 void baz2() throw(int, char, int){} // duplicates are ignored
40 void baz3() throw(int, char);
41 void baz3() throw(Int, char){} // typedefs are the same type ...
43 void baz4() throw(int, Int, char); // ... so this is a duplicate
44 void baz4() throw(Int, char){}
46 void fna() throw(int, char); // { dg-error "" } to previous declaration
47 void fna() throw(int const, char); // { dg-error "" } declaration different exceptions // ERROR - to previous declaration
48 void fna() throw(int){} // { dg-error "" } declaration different exceptions
50 void fnb() throw(int, char); // { dg-error "" } to previous declaration
51 void fnb() throw(char){} // { dg-error "" } declaration different exceptions
53 void fnc() throw(int, char); // { dg-error "" } to previous declaration
54 void fnc() throw(char, int, float){} // { dg-error "" } declaration different exceptions
56 void fnd() throw(); // { dg-error "" } to previous declaration
57 void fnd() throw(char){} // { dg-error "" } declaration different exceptions
59 void fne() throw(char); // { dg-error "" } to previous declaration
60 void fne() throw(){} // { dg-error "" } declaration different exceptions
62 void fnf(); // { dg-error "" } to previous declaration
63 void fnf() throw(char){} // { dg-error "" } declaration different exceptions
65 void fng() throw(char); // { dg-error "" } to previous declaration
66 void fng(){} // { dg-error "" } declaration different exceptions
68 void fnh() throw(int, char); // { dg-error "" } to previous declaration
69 void fnh() throw(int, float){} // { dg-error "" } declaration different exceptions
71 void fni() throw(int, char); // { dg-error "" } to previous declaration
72 void fni() throw(float, char){} // { dg-error "" } declaration different exceptions
74 // [except.spec] 3, virtual function overriders shall throw a subset of the
75 // overridden function
77 struct F : public E {};
78 struct F1 : public E {};
79 struct G : public F, F1 {};
80 struct H : private E {};
83 virtual void foo() throw(); // { dg-error "" } overriding
84 virtual void baz() throw(double, int);
86 virtual void qux() throw(E);
87 virtual void qux(int) throw(E const *); // { dg-error "" } overriding (pedantically)
88 virtual void quux() throw(F); // { dg-error "" } overriding
89 virtual void quux(int) throw(F *); // { dg-error "" } overriding
90 virtual void wibble() throw(E); // { dg-error "" } overriding
91 virtual void wobble() throw(E *); // { dg-error "" } overriding
92 virtual void wobble(int) throw(E *); // { dg-error "" } overriding
93 virtual void wabble(int) throw(E *);
94 virtual void wubble(int) throw(E *, H *);
95 virtual ~A() throw(); // { dg-error "" } overriding
100 virtual void foo() throw(int); // { dg-error "" } looser throw - A::foo
101 virtual void baz() throw(double); // ok subset
102 virtual void bar(int) throw(int); // ok not overriding
103 virtual void qux() throw(F); // ok subset
104 virtual void qux(int) throw(F *); // { dg-error "" } looser (pedantically)
105 virtual void quux() throw(E); // { dg-error "" } looser throw - A::quux()
106 virtual void quux(int) throw(E *); // { dg-error "" } looser throw - A::quux(int)
107 virtual void wibble() throw(E *); // { dg-error "" } looser throw - A::wibble
108 virtual void wobble() throw(G *); // { dg-error "" } looser throw - A::wobble()
109 virtual void wobble(int) throw(H *); // { dg-error "" } looser throw - A::wobble(int)
110 virtual void wubble(int) throw(H *); // ok
111 virtual void wabble(int) throw(F1 *, F *); // ok
116 virtual void foo() throw(int);
117 virtual void bar() throw(); // { dg-error "" } overriding
118 virtual ~A1() throw(int);
126 { // { dg-error "" } looser throw - A::~A()
127 virtual void foo() throw(int); // { dg-error "" } looser throw - A::foo
128 virtual void bar() throw(int); // { dg-error "" } looser throw - A1::bar
133 virtual ~D() throw(int); // { dg-error "" } looser throw - A::~A()
136 // [except.spec] 5, types shall not be defined in exception specifiers
137 void fn8() throw(struct Z {}); // { dg-error "" } ANSI C++ forbids