2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.eh / spec6.C
blobb9ccd6e83693085a7fc8bced65f0621ac88730f8
1 // { dg-do assemble  }
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
25 void fx()
27   fnx((int *)0);
28   fnx((void *)0);               // { dg-error "" } instantiated from here
31 // [except.spec] 2, exception specifiers must be the same set of types (but
32 // can be reordered)
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
39 typedef int Int;
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
76 struct E {};
77 struct F : public E {};
78 struct F1 : public E {};
79 struct G : public F, F1 {};
80 struct H : private E {};
81 struct A
83   virtual void foo() throw();             // { dg-error "" } overriding 
84   virtual void baz() throw(double, int);
85   virtual void bar();
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
98 struct B : A
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
114 struct A1
116   virtual void foo() throw(int);
117   virtual void bar() throw();       // { dg-error "" } overriding 
118   virtual ~A1() throw(int);
121 struct B1 : A
125 struct C : A, A1
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
131 struct D : A, A1
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