1 // RUN: %clang_cc1 -std=c++23 -verify %s 2 3 namespace PR52206 { f()4constexpr 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}} 7 } 8 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}} 12 } 13 14 constexpr auto h() { 15 if consteval { return 0; } 16 if !consteval { return 0; } // okay 17 } 18 19 constexpr auto i() { 20 if consteval { 21 if consteval { // expected-warning {{consteval if is always true in an immediate context}} 22 return 1; 23 } 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}} 27 } 28 } 29 30 void test() { 31 auto x1 = f(); 32 constexpr auto y1 = f(); 33 34 auto x2 = g(); 35 constexpr auto y2 = g(); 36 37 auto x3 = h(); 38 constexpr auto y3 = h(); 39 40 auto x4 = i(); 41 constexpr auto y4 = i(); 42 } 43 } // namespace PR52206 44 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; 53 } 54 } 55 return 0.0; 56 } 57