58 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s2// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s -fexperimental-new-constant-interpreter3 4namespace std {5constexpr bool is_constant_evaluated() noexcept {6 return __builtin_is_constant_evaluated();7}8} // namespace std9 10constexpr 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 else14 return 1;15}16 17constexpr 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 else21 return 1;22}23 24constexpr 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 else28 return 1;29}30 31constexpr 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 else35 return 1;36}37 38constexpr 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 else42 return 1;43}44 45constexpr int nowarn1() {46 if (std::is_constant_evaluated())47 return 0;48 else49 return 1;50}51 52constexpr int nowarn2() {53 if (!__builtin_is_constant_evaluated())54 return 0;55 else56 return 1;57}58