[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / warn-constant-evaluated-constexpr.cpp
blobfa40c13971118da4564c7d3c1691183b5deb701b
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
4 namespace std {
5 constexpr bool is_constant_evaluated() noexcept {
6 return __builtin_is_constant_evaluated();
8 } // namespace std
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;
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;
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;
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;
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;
45 constexpr int nowarn1() {
46 if (std::is_constant_evaluated())
47 return 0;
48 else
49 return 1;
52 constexpr int nowarn2() {
53 if (!__builtin_is_constant_evaluated())
54 return 0;
55 else
56 return 1;