| 1 |
// P0595R2 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 4 |
namespace std { |
| 5 |
constexpr inline bool |
| 6 |
is_constant_evaluated () noexcept |
| 7 |
{ |
| 8 |
return __builtin_is_constant_evaluated (); |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
int a; |
| 13 |
|
| 14 |
constexpr bool |
| 15 |
foo (int x) |
| 16 |
{ |
| 17 |
return __builtin_constant_p (x); |
| 18 |
} |
| 19 |
|
| 20 |
constexpr bool |
| 21 |
bar (int x) |
| 22 |
{ |
| 23 |
return __builtin_constant_p (x + a); |
| 24 |
} |
| 25 |
|
| 26 |
static_assert (__builtin_constant_p (0) + 2 * std::is_constant_evaluated () == 3, ""); |
| 27 |
static_assert (__builtin_constant_p (a) + 2 * std::is_constant_evaluated () == 2, ""); |
| 28 |
static_assert (foo (0) + 2 * std::is_constant_evaluated () == 3, ""); |
| 29 |
static_assert (bar (0) + 2 * std::is_constant_evaluated () == 2, ""); |