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; // ERROR - forward declaration.*
11 void fn1() throw(X); // ERROR - invalid use of undefined type
12 void fn2() throw(X *); // ERROR - invalid use of undefined type
13 void fn3() throw(X &); // ERROR - invalid use of undefined tyoe
14 void fn4() throw(void); // ERROR - invalid use of void expression
15 void fn5() throw(void &); // 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); // ERROR - invalid use of void
24 template<class T> void fnx(T *) throw(T){} // ERROR - invalid use of void expression
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); // ERROR - to previous declaration
47 void fna() throw(int const, char); // ERROR - declaration different exceptions // ERROR - to previous declaration
48 void fna() throw(int){} // ERROR - declaration different exceptions
50 void fnb() throw(int, char); // ERROR - to previous declaration
51 void fnb() throw(char){} // ERROR - declaration different exceptions
53 void fnc() throw(int, char); // ERROR - to previous declaration
54 void fnc() throw(char, int, float){} // ERROR - declaration different exceptions
56 void fnd() throw(); // ERROR - to previous declaration
57 void fnd() throw(char){} // ERROR - declaration different exceptions
59 void fne() throw(char); // ERROR - to previous declaration
60 void fne() throw(){} // ERROR - declaration different exceptions
62 void fnf(); // ERROR - to previous declaration
63 void fnf() throw(char){} // ERROR - declaration different exceptions
65 void fng() throw(char); // ERROR - to previous declaration
66 void fng(){} // ERROR - declaration different exceptions
68 void fnh() throw(int, char); // ERROR - to previous declaration
69 void fnh() throw(int, float){} // ERROR - declaration different exceptions
71 void fni() throw(int, char); // ERROR - to previous declaration
72 void fni() throw(float, char){} // 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(); // ERROR - overriding
84 virtual void baz() throw(double, int);
86 virtual void qux() throw(E);
87 virtual void qux(int) throw(E const *); // ERROR - overriding (pedantically)
88 virtual void quux() throw(F); // ERROR - overriding
89 virtual void quux(int) throw(F *); // ERROR - overriding
90 virtual void wibble() throw(E); // ERROR - overriding
91 virtual void wobble() throw(E *); // ERROR - overriding
92 virtual void wobble(int) throw(E *); // ERROR - overriding
93 virtual void wabble(int) throw(E *);
94 virtual void wubble(int) throw(E *, H *);
95 virtual ~A() throw(); // ERROR - overriding
100 virtual void foo() throw(int); // 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 *); // ERROR - looser (pedantically)
105 virtual void quux() throw(E); // ERROR - looser throw - A::quux()
106 virtual void quux(int) throw(E *); // ERROR - looser throw - A::quux(int)
107 virtual void wibble() throw(E *); // ERROR - looser throw - A::wibble
108 virtual void wobble() throw(G *); // ERROR - looser throw - A::wobble()
109 virtual void wobble(int) throw(H *); // 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(); // ERROR - overriding
118 virtual ~A1() throw(int);
126 { // ERROR - looser throw - A::~A()
127 virtual void foo() throw(int); // ERROR - looser throw - A::foo
128 virtual void bar() throw(int); // ERROR - looser throw - A1::bar
133 virtual ~D() throw(int); // ERROR - looser throw - A::~A()
136 // [except.spec] 5, types shall not be defined in exception specifiers
137 void fn8() throw(struct Z {}); // ERROR - ANSI C++ forbids