blob: 8e230ef3bc3ab4c6809e59f28e4c52a628eddbe3 (
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
|
// P2647R1 - Permitting static constexpr variables in constexpr functions
// { dg-do compile { target c++14 } }
constexpr int
f1 (int x)
{
if (x)
throw 1;
return 0;
}
constexpr int
f2 ()
{
static const int a = f1 (1); // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
return 0;
}
constexpr int
f3 ()
{
static const int a = 5; // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
return 0;
}
constexpr int
f4 () // { dg-message "declared here" "" { target c++20_down } }
{ // { dg-message "is not usable as a 'constexpr' function because:" "" { target c++23 } .-1 }
static const int a = f1 (1); // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
return 0; // { dg-error "'a' defined 'static' in 'constexpr' context" "" { target c++23 } .-1 }
}
constexpr int a4 = f4 (); // { dg-error "called in a constant expression" }
constexpr int
f5 ()
{
static const int a = f1 (0); // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
return 0;
}
constexpr int
f6 ()
{
static const int a = f1 (0); // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
return 0;
}
constexpr int a6 = f6 (); // { dg-error "called in a constant expression" "" { target c++20_down } }
|