[Clang] Confusing diagnostics on constexpr bit cast with casted pointer
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
From https://github.com/llvm/llvm-project/pull/184865, we see that
```cpp
#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
constexpr long fn(void) {
return __builtin_bit_cast(long, fold((long)&fn));
}
static_assert(fn() == 1);
```
is showing this diagnostics
```
:6:15: error: static assertion expression is not an integral constant expression
6 | static_assert(fn() == 1);
| ^~~~~~~~~
:4:10: note: constexpr bit cast involving type 'long' is not yet supported
4 | return __builtin_bit_cast(long, fold((long)&fn));
| ^
:6:15: note: in call to 'fn()'
6 | static_assert(fn() == 1);
| ^~~~
1 error generated.
```
The message "constexpr bit cast involving type 'long' is not yet supported" is a bit confusing because `long` is actually supported and the real issue is that it's from a non-const value.
Compiler Explorer: https://godbolt.org/z/b85rxb5xe
Contributor guide
Assessment
This issue has not been assessed yet.