blob: c60fb8cdbd8aec78db26573c9dceb5192a1a6750 (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// P2242R3
// { dg-do compile { target c++14 } }
constexpr int
foo ()
{
lab: // { dg-error "label definition in 'constexpr' function only available with" "" { target c++20_down } }
return 1;
}
constexpr int
bar (int x)
{
if (x)
goto lab; // { dg-error "'goto' in 'constexpr' function only available with" "" { target c++20_down } }
return 1;
lab:
return 0;
}
constexpr int
baz (int x)
{
if (!x)
return 1;
static int a; // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
return ++a; // { dg-error "uninitialized variable 'a' in 'constexpr' function" "" { target c++17_down } .-1 }
}
constexpr int
qux (int x)
{
if (!x)
return 1;
thread_local int a; // { dg-error "'a' defined 'thread_local' in 'constexpr' function only available with" "" { target c++20_down } }
return ++a; // { dg-error "uninitialized variable 'a' in 'constexpr' function" "" { target c++17_down } .-1 }
}
constexpr int
garply (int x)
{
if (!x)
return 1;
extern thread_local int a; // { dg-bogus "'thread_local' in 'constexpr' function only available with" "" { target c++20_down } }
return ++a;
}
struct S { S (); ~S (); int s; }; // { dg-message "'S' is not literal because:" "" { target c++20_down } }
// { dg-message "'S' has a non-trivial destructor" "" { target c++17_down } .-1 }
// { dg-message "'S' does not have 'constexpr' destructor" "" { target { c++20_only } } .-2 }
constexpr int
corge (int x)
{
if (!x)
return 1;
S s; // { dg-error "variable 's' of non-literal type 'S' in 'constexpr' function only available with" "" { target c++20_down } }
return 0;
}
#if __cpp_constexpr >= 202110L
static_assert (foo ());
static_assert (bar (0));
static_assert (baz (0));
static_assert (qux (0));
static_assert (garply (0));
static_assert (corge (0));
#endif
|