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