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