Clang rejects gcc extension of allowing vector reinterpret_cast in constant expressions
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
[Test case](https://compiler-explorer.com/z/Eh4erPMsq):
```c++
using V0 [[gnu::vector_size(16)]] = int;
using V1 [[gnu::vector_size(16)]] = float;
constexpr V0 x = reinterpret_cast(V1());
```
GCC set the precedent of bit-casting vectors via `reinterpret_cast`. It does so with additional semantic information (i.e. higher quality diagnostics on errors), which is why the libstdc++ std::simd implementation prefers `reinterpret_cast` over `std::bit_cast`. However, Clang rejects these casts in constant expressions, which is incompatible to GCC.
Proposed resolution: Allow "reinterpret-cast by value of GNU vectors" in constant expressions.
Contributor guide
Research direction
Start with the linked Compiler Explorer test case and inspect Clang's constant-expression handling for GNU vector reinterpret_cast expressions. Compare the behavior with GCC and the stated libstdc++ std::simd use case. Done means the shown constexpr cast is accepted by Clang while invalid cases retain useful diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100