Home | History | Annotate | Download | only in except.spec
      1 // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
      2 
      3 // Assignment of function pointers.
      4 
      5 struct A
      6 {
      7 };
      8 
      9 struct B1 : A
     10 {
     11 };
     12 
     13 struct B2 : A
     14 {
     15 };
     16 
     17 struct D : B1, B2
     18 {
     19 };
     20 
     21 struct P : private A
     22 {
     23 };
     24 
     25 // Some functions to play with below.
     26 void s1() throw();
     27 void s2() throw(int);
     28 void s3() throw(A);
     29 void s4() throw(B1);
     30 void s5() throw(D);
     31 void s6();
     32 void s7() throw(int, float);
     33 void (*s8())() throw(B1); // s8 returns a pointer to function with spec
     34 void s9(void (*)() throw(B1)); // s9 takes pointer to function with spec
     35 
     36 void s10() noexcept;
     37 void s11() noexcept(true);
     38 void s12() noexcept(false);
     39 
     40 void fnptrs()
     41 {
     42   // Assignment and initialization of function pointers.
     43   void (*t1)() throw() = &s1;    // valid
     44   t1 = &s2;                      // expected-error {{not superset}} expected-error {{incompatible type}}
     45   t1 = &s3;                      // expected-error {{not superset}} expected-error {{incompatible type}}
     46   void (&t2)() throw() = s2;     // expected-error {{not superset}}
     47   void (*t3)() throw(int) = &s2; // valid
     48   void (*t4)() throw(A) = &s1;   // valid
     49   t4 = &s3;                      // valid
     50   t4 = &s4;                      // valid
     51   t4 = &s5;                      // expected-error {{not superset}} expected-error {{incompatible type}}
     52   void (*t5)() = &s1;            // valid
     53   t5 = &s2;                      // valid
     54   t5 = &s6;                      // valid
     55   t5 = &s7;                      // valid
     56   t1 = t3;                       // expected-error {{not superset}} expected-error {{incompatible type}}
     57   t3 = t1;                       // valid
     58   void (*t6)() throw(B1);
     59   t6 = t4;                       // expected-error {{not superset}} expected-error {{incompatible type}}
     60   t4 = t6;                       // valid
     61   t5 = t1;                       // valid
     62   t1 = t5;                       // expected-error {{not superset}} expected-error {{incompatible type}}
     63 
     64   // return types and arguments must match exactly, no inheritance allowed
     65   void (*(*t7)())() throw(B1) = &s8;       // valid
     66   void (*(*t8)())() throw(A) = &s8;        // expected-error {{return types differ}}
     67   void (*(*t9)())() throw(D) = &s8;        // expected-error {{return types differ}}
     68   void (*t10)(void (*)() throw(B1)) = &s9; // valid
     69   void (*t11)(void (*)() throw(A)) = &s9;  // expected-error {{argument types differ}}
     70   void (*t12)(void (*)() throw(D)) = &s9;  // expected-error {{argument types differ}}
     71 }
     72 
     73 // Member function stuff
     74 
     75 struct Str1 { void f() throw(int); }; // expected-note {{previous declaration}}
     76 void Str1::f() // expected-error {{missing exception specification}}
     77 {
     78 }
     79 
     80 void mfnptr()
     81 {
     82   void (Str1::*pfn1)() throw(int) = &Str1::f; // valid
     83   void (Str1::*pfn2)() = &Str1::f; // valid
     84   void (Str1::*pfn3)() throw() = &Str1::f; // expected-error {{not superset}}
     85 }
     86