clang -Wunreachable-code triggers on instantiation of classes with [[noreturn]] constructors
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer -- [godbolt](https://gcc.godbolt.org/z/7vrrKj98d):
Compiling
```cpp
#include
struct NoReturn {
[[noreturn]] NoReturn() {
exit(123);
}
};
int main(int argc, char** argv) {
NoReturn n;
}
```
(edited to simplify a bit more)
With `-std=c++26 -Wunreachable-code` this yields the following warning, while the code clearly does execute:
```
:10:5: warning: code will never be executed [-Wunreachable-code]
10 | NoReturn n;
| ^~~~~~~~~~~
1 warning generated.
Execution build compiler returned: 0
Program returned: 123
```
I've reproduced this locally and on godbolt with `21.1.8`, `21.1.0` and `20.1.0`. It does not reproduce with `19.1.0`.
(and yes, I have a real use case for `[[noreturn]]` constructors! :) )
Contributor guide
Assessment
This issue has not been assessed yet.