Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/constexpr-nonlit2.C

raw
1 // P2242R3
2 // { dg-do compile }
3 // { dg-options "-std=c++2b" }
4
5 constexpr int
6 foo ()
7 {
8 lab:
9 return 1;
10 }
11
12 constexpr int
13 bar (int x)
14 {
15 if (x)
16 goto lab; // { dg-error "'goto' is not a constant expression" }
17 return 1;
18 lab:
19 return 0;
20 }
21
22 constexpr int
23 baz (int x)
24 {
25 if (!x)
26 return 1;
27 static int a; // { dg-error "control passes through definition of 'a' with static storage duration" }
28 return ++a;
29 }
30
31 constexpr int
32 qux (int x)
33 {
34 if (!x)
35 return 1;
36 thread_local int a; // { dg-error "control passes through definition of 'a' with thread storage duration" }
37 return ++a;
38 }
39
40 struct S { S (); ~S (); int s; }; // { dg-message "'S::S\\\(\\\)' declared here" }
41
42 constexpr int
43 corge (int x)
44 {
45 if (!x)
46 return 1;
47 S s; // { dg-error "call to non-'constexpr' function 'S::S\\\(\\\)'" }
48 return 0;
49 }
50
51 constexpr int a = bar (1); // { dg-message "in 'constexpr' expansion of" }
52 constexpr int b = baz (1); // { dg-message "in 'constexpr' expansion of" }
53 constexpr int c = qux (1); // { dg-message "in 'constexpr' expansion of" }
54 constexpr int d = corge (1); // { dg-message "in 'constexpr' expansion of" }