-Winvalid-static-assert-message is too aggressive
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Consider:
```c++
constexpr std::expected validate(/* some stuff */);
constexpr auto r = validate(...);
static_assert(r, r.error());
```
Clang will [pointlessly complain](https://gcc.godbolt.org/z/KjY3j97xr):
```
:10:18: error: the message in this static assertion is not a constant expression [-Winvalid-static-assert-message]
10 | static_assert(r, r.error());
| ^
:10:18: note: member call on member '__unex_' of union with active member '__empty_' is not allowed in a constant expression
```
Well, presumably [that's why it's an unevaluated operand](https://eel.is/c++draft/dcl.pre#13.sentence-2)!
If the validation fails, then it will be a constant expression.
It's one thing to warn if the type of the message is such that it could never be constant. It's another to force contortions in code written to the spec that doesn't actually provide any value whatsoever. Especially when/if the `static_assert` actually fails, you get an error _anyway_ even if the expression is bogus.
Contributor guide
Assessment
This issue has not been assessed yet.