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