public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114537] New: bit_cast does not work NSDMI of bitfields
@ 2024-03-31 19:33 pinskia at gcc dot gnu.org
  2024-04-01  9:40 ` [Bug c++/114537] " fchelnokov at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-31 19:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114537
           Summary: bit_cast does not work NSDMI of bitfields
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: FIXME
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
#include <bit>

struct A {  signed char b:1 = 0; signed char b1:7 = 0; };

struct B { unsigned char b; };

static_assert( std::bit_cast<B>(A{}).b == 0 );
```

This should work as the bitfields span all of the char space but currently we
get a sorry:
```
<source>:9:40: error: non-constant condition for static assertion
    9 | static_assert( std::bit_cast<B>(A{}).b == 0 );
      |                ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
In file included from <source>:2:
<source>:9:32:   in 'constexpr' expansion of 'std::bit_cast<B, A>(A{0, 0})'
/opt/compiler-explorer/gcc-trunk-20240331/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);
      |                                 ^~~
```

I had been looking for a quick workaround for PR 114536 (for little-endian
only) but it looked like NSDMI for bitfields is not implemented fully.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-06-20 13:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-31 19:33 [Bug c++/114537] New: bit_cast does not work NSDMI of bitfields pinskia at gcc dot gnu.org
2024-04-01  9:40 ` [Bug c++/114537] " fchelnokov at gmail dot com
2024-04-01 13:54 ` pinskia at gcc dot gnu.org
2024-04-03 15:10 ` jakub at gcc dot gnu.org
2024-04-04  8:48 ` cvs-commit at gcc dot gnu.org
2024-04-05 18:44 ` fchelnokov at gmail dot com
2024-04-21  4:08 ` cvs-commit at gcc dot gnu.org
2024-06-11 10:37 ` cvs-commit at gcc dot gnu.org
2024-06-11 10:57 ` jakub at gcc dot gnu.org
2024-06-20 13:22 ` cvs-commit at gcc dot gnu.org
2024-06-20 13:39 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).