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