https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114537

--- Comment #5 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
Sorry, in above example I had to use `unsigned char` type:

```
#include <bit>

struct A { unsigned char a : 7; };

static_assert( std::bit_cast<A>(std::bit_cast<unsigned char>(A{1})).a == 1 );
```

This program even after the fix in trunk, prints the same error as in the
original post:
<source>:5:32:   in 'constexpr' expansion of 'std::bit_cast<A, unsigned
char>(std::bit_cast<unsigned char, A>(A{1}))'
/opt/compiler-explorer/gcc-trunk-20240405/include/c++/14.0.1/bit:94:33: sorry,
unimplemented: '__builtin_bit_cast' cannot be constant evaluated because the
argument cannot be encoded
   94 |       return __builtin_bit_cast(_To, __from);

Online demo: https://gcc.godbolt.org/z/eqrsfGEnT
  • [Bug c++/114537] bit_cast does ... fchelnokov at gmail dot com via Gcc-bugs

Reply via email to