[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CXX / except / except.spec / p5-pointers.cpp
blobdedc5bd376f921108edc3241ee15d92f74bef0c3
1 // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
3 // Assignment of function pointers.
5 struct A
7 };
9 struct B1 : A
13 struct B2 : A
17 struct D : B1, B2
21 struct P : private A
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
36 void s10() noexcept;
37 void s11() noexcept(true);
38 void s12() noexcept(false);
40 void fnptrs()
42 // Assignment and initialization of function pointers.
43 void (*t1)() throw() = &s1; // valid
44 t1 = &s2; // expected-error {{not superset}}
45 t1 = &s3; // expected-error {{not superset}}
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}}
52 void (*t5)() = &s1; // valid
53 t5 = &s2; // valid
54 t5 = &s6; // valid
55 t5 = &s7; // valid
56 t1 = t3; // expected-error {{not superset}}
57 t3 = t1; // valid
58 void (*t6)() throw(B1);
59 t6 = t4; // expected-error {{not superset}}
60 t4 = t6; // valid
61 t5 = t1; // valid
62 t1 = t5; // expected-error {{not superset}}
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}}
73 // Member function stuff
75 struct Str1 { void f() throw(int); }; // expected-note {{previous declaration}}
76 void Str1::f() // expected-error {{missing exception specification}}
80 void mfnptr()
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}}