Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated15.C

raw
1 // PR c++/114580
2 // { dg-do compile { target c++17 } }
3 // { dg-options "-Wtautological-compare" }
4
5 namespace std {
6 constexpr inline bool
7 is_constant_evaluated () noexcept
8 {
9 #if __cpp_if_consteval >= 202106L
10 if consteval { return true; } else { return false; }
11 #else
12 return __builtin_is_constant_evaluated ();
13 #endif
14 }
15 }
16
17 template <typename T>
18 void foo ()
19 {
20 if constexpr ((T) std::is_constant_evaluated ()) // { dg-warning "'std::is_constant_evaluated' always evaluates to true in 'if constexpr'" }
21 ; // { dg-bogus "'std::is_constant_evaluated' always evaluates to false in a non-'constexpr' function" }
22 }
23
24 void
25 bar ()
26 {
27 foo <bool> ();
28 }