[clang] [Clang] avoid adding consteval condition as the last statement to preserve valid CFG (PR #116513)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 19 11:08:22 PST 2024
================
@@ -5,3 +5,9 @@ static_assert(__is_same(decltype([] constexpr -> int { }( )), int)); // expected
consteval int g() { } // expected-warning {{non-void function does not return a value}}
static_assert(__is_same(decltype([] consteval -> int { }( )), int)); // expected-warning {{non-void lambda does not return a value}}
+
+namespace GH116485 {
+int h() {
+ if consteval { }
+} // expected-warning {{non-void function does not return a value}}
----------------
AaronBallman wrote:
Other test cases to add are:
```
void foo(int x) {
if consteval {
}
switch (x) {
case 1:
foo(12); // Should get a `-Wimplicit-fallthrough` warning here
case 2:
break;
}
}
```
https://godbolt.org/z/rns3Yjofq
or testing whether the consteval if actually causes an early return:
```
constexpr bool foo() {
if !consteval { return true; }
}
bool b = foo();
constinit bool c = foo();
```
https://github.com/llvm/llvm-project/pull/116513
More information about the cfe-commits
mailing list