Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / cxx2b-consteval-if.cpp
blob72ba58b676247f84a21305a1dbd6bdaba2e17827
1 // RUN: %clang_cc1 -std=c++23 -verify %s
3 namespace PR52206 {
4 constexpr auto f() {
5 if consteval { return 0; }
6 if !consteval { return 0.0; } // expected-error {{'auto' in return type deduced as 'double' here but deduced as 'int' in earlier return statement}}
9 constexpr auto g() {
10 if !consteval { return 0; }
11 if consteval { return 0.0; } // expected-error {{'auto' in return type deduced as 'double' here but deduced as 'int' in earlier return statement}}
14 constexpr auto h() {
15 if consteval { return 0; }
16 if !consteval { return 0; } // okay
19 constexpr auto i() {
20 if consteval {
21 if consteval { // expected-warning {{consteval if is always true in an immediate context}}
22 return 1;
24 return 2;
25 } else {
26 return 1.0; // expected-error {{'auto' in return type deduced as 'double' here but deduced as 'int' in earlier return statement}}
30 void test() {
31 auto x1 = f();
32 constexpr auto y1 = f();
34 auto x2 = g();
35 constexpr auto y2 = g();
37 auto x3 = h();
38 constexpr auto y3 = h();
40 auto x4 = i();
41 constexpr auto y4 = i();
43 } // namespace PR52206
45 consteval int *make() { return new int; }
46 auto f() {
47 if constexpr (false) {
48 if consteval {
49 // Immediate function context, so call to `make()` is valid.
50 // Discarded statement context, so `return 0;` is valid too.
51 delete make();
52 return 0;
55 return 0.0;