| 1 |
// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s |
| 2 |
// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s -fexperimental-new-constant-interpreter |
| 3 |
|
| 4 |
namespace std { |
| 5 |
constexpr bool is_constant_evaluated() noexcept { |
| 6 |
return __builtin_is_constant_evaluated(); |
| 7 |
} |
| 8 |
} // namespace std |
| 9 |
|
| 10 |
constexpr int fn1() { |
| 11 |
if constexpr (std::is_constant_evaluated()) // expected-warning {{'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression}} |
| 12 |
return 0; |
| 13 |
else |
| 14 |
return 1; |
| 15 |
} |
| 16 |
|
| 17 |
constexpr int fn2() { |
| 18 |
if constexpr (!std::is_constant_evaluated()) // expected-warning {{'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression}} |
| 19 |
return 0; |
| 20 |
else |
| 21 |
return 1; |
| 22 |
} |
| 23 |
|
| 24 |
constexpr int fn3() { |
| 25 |
if constexpr (std::is_constant_evaluated() == false) // expected-warning {{'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression}} |
| 26 |
return 0; |
| 27 |
else |
| 28 |
return 1; |
| 29 |
} |
| 30 |
|
| 31 |
constexpr int fn4() { |
| 32 |
if constexpr (__builtin_is_constant_evaluated() == true) // expected-warning {{'__builtin_is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression}} |
| 33 |
return 0; |
| 34 |
else |
| 35 |
return 1; |
| 36 |
} |
| 37 |
|
| 38 |
constexpr int fn5() { |
| 39 |
if constexpr (__builtin_is_constant_evaluated()) // expected-warning {{'__builtin_is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression}} |
| 40 |
return 0; |
| 41 |
else |
| 42 |
return 1; |
| 43 |
} |
| 44 |
|
| 45 |
constexpr int nowarn1() { |
| 46 |
if (std::is_constant_evaluated()) |
| 47 |
return 0; |
| 48 |
else |
| 49 |
return 1; |
| 50 |
} |
| 51 |
|
| 52 |
constexpr int nowarn2() { |
| 53 |
if (!__builtin_is_constant_evaluated()) |
| 54 |
return 0; |
| 55 |
else |
| 56 |
return 1; |
| 57 |
} |