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