Clang Project

clang_source_code/test/CXX/conv/conv.fctptr/p1.cpp
1// RUN: %clang_cc1 -std=c++1z -verify %s -triple x86_64-unknown-unknown
2
3struct S;
4
5typedef void Nothrow() noexcept;
6typedef void Throw();
7
8Nothrow *a;
9Throw *b;
10Nothrow S::*c;
11Throw S::*d;
12
13void test() {
14  a = b; // expected-error {{assigning to 'Nothrow *' (aka 'void (*)() noexcept') from incompatible type 'Throw *' (aka 'void (*)()'): different exception specifications}}
15  b = a;
16  c = d; // expected-error {{assigning to 'Nothrow S::*' from incompatible type 'Throw S::*': different exception specifications}}
17  d = c;
18
19  // Function pointer conversions do not combine properly with qualification conversions.
20  // FIXME: This seems like a defect.
21  Nothrow *const *pa = b; // expected-error {{cannot initialize}}
22  Throw *const *pb = a; // expected-error {{cannot initialize}}
23  Nothrow *const S::*pc = d; // expected-error {{cannot initialize}}
24  Throw *const S::*pd = c; // expected-error {{cannot initialize}}
25}
26
27// ... The result is a pointer to the function.
28void f() noexcept;
29constexpr void (*p)() = &f;
30static_assert(f == p);
31
32struct S { void f() noexcept; };
33constexpr void (S::*q)() = &S::f;
34static_assert(q == &S::f);
35
36
37namespace std_example {
38  void (*p)();
39  void (**pp)() noexcept = &p; // expected-error {{cannot initialize a variable of type 'void (**)() noexcept' with an rvalue of type 'void (**)()'}}
40
41  struct S { typedef void (*p)(); operator p(); }; // expected-note {{candidate}}
42  void (*q)() noexcept = S(); // expected-error {{no viable conversion from 'std_example::S' to 'void (*)() noexcept'}}
43}
44