Issue |
120211
|
Summary |
`__builtin_bit_cast` to `bool` diverges from GCC's behavior
|
Labels |
clang:frontend,
constexpr
|
Assignees |
|
Reporter |
tbaederr
|
This is the specific case:
```c++
constexpr bool A = __builtin_bit_cast(bool, 'A');
static_assert(A);
```
GCC happily compiles this while clang prints an error:
```
array.cpp:128:16: error: constexpr variable 'a' must be initialized by a constant _expression_
128 | constexpr bool a = __builtin_bit_cast(bool, 'A');
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
array.cpp:128:20: note: value 65 cannot be represented in type 'bool'
128 | constexpr bool a = __builtin_bit_cast(bool, 'A');
| ^
```
This specific diagnostic is tested exactly _once_, in `SemaCXX/constexpr-builtin-bit-cast.cpp`. It's an edge case which clang checks for all integral types though:
https://github.com/llvm/llvm-project/blob/0693b9e9ccdec5f09a3080b1bec73f5004a8dfa3/clang/lib/AST/ExprConstant.cpp#L7495-L7507
I think the relevant part from https://eel.is/c++draft/bit.cast is
> For the result and each object created within it, if there is no value of the object's type corresponding to the value representation produced, the behavior is undefined[.](https://eel.is/c++draft/bit.cast#2.sentence-5)
If there are multiple such values, which value is produced is unspecified[.](https://eel.is/c++draft/bit.cast#2.sentence-6)
Does the first sentence apply here or the second?
CC @zygoloid
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs