Debian Codegraph @

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

raw
1 // P2242R3
2 // { dg-do compile }
3 // { dg-options "-std=c++2b" }
4
5 constexpr int
6 foo ()
7 {
8 goto lab; // { dg-error "'goto' is not a constant expression" }
9 lab:
10 return 1;
11 }
12
13 constexpr int
14 bar ()
15 {
16 static int a; // { dg-error "'a' defined 'static' in 'constexpr' context" }
17 return ++a;
18 }
19
20 constexpr int
21 baz ()
22 {
23 thread_local int a; // { dg-error "'a' defined 'thread_local' in 'constexpr' context" }
24 return ++a;
25 }
26
27 // In C++23, we get errors about the non-constant expressions only if we
28 // actually call the functions in a constexpr context.
29
30 void
31 test ()
32 {
33 constexpr int a = foo (); // { dg-error "constant expression" }
34 constexpr int b = bar (); // { dg-error "constant expression" }
35 constexpr int c = baz (); // { dg-error "constant expression" }
36 }