public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114536] New: wrong constant evaluation of std::bit_cast for bit fields
@ 2024-03-31 10:13 fchelnokov at gmail dot com
  2024-03-31 10:19 ` [Bug c++/114536] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: fchelnokov at gmail dot com @ 2024-03-31 10:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114536
           Summary: wrong constant evaluation of std::bit_cast for bit
                    fields
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In this program


#include <bit>

struct A { unsigned char a: 7; };

struct B { unsigned char b; };

// fails in GCC
static_assert( std::bit_cast<B>(A{1}).b == 1 );

int main() {
    // correctly returns 1 in GCC
    return std::bit_cast<B>(A{1}).b;
}


static_assert fails with the message:

note: the comparison reduces to '(0 == 1)'

which contradicts runtime evaluation of the same expression. Online demo:
https://gcc.godbolt.org/z/fza4zas3E

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

end of thread, other threads:[~2024-04-03 15:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-31 10:13 [Bug c++/114536] New: wrong constant evaluation of std::bit_cast for bit fields fchelnokov at gmail dot com
2024-03-31 10:19 ` [Bug c++/114536] " pinskia at gcc dot gnu.org
2024-03-31 10:22 ` fchelnokov at gmail dot com
2024-03-31 10:25 ` pinskia at gcc dot gnu.org
2024-03-31 10:26 ` redi at gcc dot gnu.org
2024-03-31 10:27 ` redi at gcc dot gnu.org
2024-03-31 19:28 ` pinskia at gcc dot gnu.org
2024-04-03 15:41 ` 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).