File: p1.cpp

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (43 lines) | stat: -rw-r--r-- 1,515 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// RUN: %clang_cc1 -std=c++1z -verify %s -triple x86_64-unknown-unknown

struct S;

typedef void Nothrow() noexcept;
typedef void Throw();

Nothrow *a;
Throw *b;
Nothrow S::*c;
Throw S::*d;

void test() {
  a = b; // expected-error {{incompatible function pointer types assigning to 'Nothrow *' (aka 'void (*)() noexcept') from 'Throw *' (aka 'void (*)()')}}
  b = a;
  c = d; // expected-error {{assigning to 'Nothrow S::*' from incompatible type 'Throw S::*': different exception specifications}}
  d = c;

  // Function pointer conversions do not combine properly with qualification conversions.
  // FIXME: This seems like a defect.
  Nothrow *const *pa = b; // expected-error {{cannot initialize}}
  Throw *const *pb = a; // expected-error {{cannot initialize}}
  Nothrow *const S::*pc = d; // expected-error {{cannot initialize}}
  Throw *const S::*pd = c; // expected-error {{cannot initialize}}
}

// ... The result is a pointer to the function.
void f() noexcept;
constexpr void (*p)() = &f;
static_assert(f == p);

struct S { void f() noexcept; };
constexpr void (S::*q)() = &S::f;
static_assert(q == &S::f);


namespace std_example {
  void (*p)();
  void (**pp)() noexcept = &p; // expected-error {{cannot initialize a variable of type 'void (**)() noexcept' with an rvalue of type 'void (**)()'}}

  struct S { typedef void (*p)(); operator p(); }; // expected-note {{candidate}}
  void (*q)() noexcept = S(); // expected-error {{no viable conversion from 'std_example::S' to 'void (*)() noexcept'}}
}