llvm / llvm/llvm-project

[Clang] Confusing diagnostics on constexpr bit cast with casted pointer

Open
#185,070 0 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.