blob: 4e33e6e3d0e016fa861d89a9b1185a5984eeee44 (
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
|
// P2564R3
// { dg-do compile { target c++20 } }
// Test default arguments.
consteval int id (int i) { return i; }
template<typename>
constexpr int
f1 (int i = id (42))
{
return i;
}
int non_const; // { dg-message ".int non_const. is not const" }
template<typename>
constexpr int
f2 (int i = id (non_const))
{
return i;
}
constexpr int
f3 (auto)
{
return f2<int>(); // { dg-message "contains an immediate-escalating expression .id\\(non_const\\)." }
}
auto a = &f3<int>; // { dg-error "taking address of an immediate function" }
void
g (int i)
{
f1<int> (42);
f1<int> (i);
f1<int> ();
f2<int> (42);
f2<int> (i);
f2<int> (); // { dg-error "call to consteval function .id\\(non_const\\). is not a constant expression" }
// { dg-error ".non_const. is not usable in a constant expression" "" { target *-*-* } .-1 }
}
|