[clang] [Clang] handle invalid close location in static assert declaration (PR #108701)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 14 17:32:54 PDT 2024


https://github.com/zyn0217 commented:

So I took a stab at it.

In `ParseStaticAssertDeclaration()`, we parsed the message in unclosed static_assert as a constant expression rather than an unevaluated string literal per the logic on lines 1079-1089.

So this approach gives up building an expression for unclosed expressions, which works but also loses the diagnoses of the condition expression where it would otherwise evaluate to false:


```cpp
static_assert(false, ""
```

Prior to clang 19, with C++11 mode, we give three errors for the above code:

https://gcc.godbolt.org/z/PMPab779n
(note the last `error: static assertion failed`)

While with this patch, we no longer diagnose it. Note that even on the assertion-free trunk with c++26 mode, we do complain about the false conditions. 

I'm not sure if this is acceptable for us.

https://github.com/llvm/llvm-project/pull/108701


More information about the cfe-commits mailing list