| 1 |
// { dg-do run } |
| 2 |
// { dg-options "-std=c++2a" } |
| 3 |
|
| 4 |
namespace std { |
| 5 |
constexpr inline bool |
| 6 |
is_constant_evaluated () noexcept |
| 7 |
{ |
| 8 |
return __builtin_is_constant_evaluated (); |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
extern "C" void abort (); |
| 13 |
template <int N> |
| 14 |
constexpr int f0 (int n) { return n + N; } |
| 15 |
template <int N> |
| 16 |
consteval int f1 (int n) { return f0<N> (n) * n + N; } |
| 17 |
template <int N> |
| 18 |
consteval int f2 (int n) { return f1<N> (n); } |
| 19 |
template <int N> |
| 20 |
consteval bool f3 () { return std::is_constant_evaluated () + N; } |
| 21 |
struct S { constexpr S (int x) : s (x) {} template <int N> consteval int m1 (int n) const; int s; }; |
| 22 |
template <int N> |
| 23 |
consteval int |
| 24 |
S::m1 (int n) const |
| 25 |
{ |
| 26 |
n += s + N; |
| 27 |
return n; |
| 28 |
} |
| 29 |
|
| 30 |
constexpr int a = 2; |
| 31 |
int b = f1<0> (a); |
| 32 |
int c = f2<0> (f1<0> (a)); |
| 33 |
bool d = f3<0> (); |
| 34 |
constexpr S e = 41; |
| 35 |
int f = e.m1<0> (1); |
| 36 |
|
| 37 |
int |
| 38 |
main () |
| 39 |
{ |
| 40 |
if (b != 4 || c != 16 || !d || f != 42) |
| 41 |
abort (); |
| 42 |
} |