https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121670
Bug ID: 121670 Summary: Replacement of integer constant with sizeof(int) makes an expression not constexpr Product: gcc Version: 15.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- In the following program GCC behaves inconsistently for two seemingly identical expressions: ``` static_assert( sizeof(int) == 4 ); char a[2*sizeof(int)]; int& p = *reinterpret_cast<int*>(a); int& q0 = *reinterpret_cast<int*>(a + 4); static_assert( &p + 1 == &q0 ); //ok in GCC int& q1 = *reinterpret_cast<int*>(a + sizeof(int)); static_assert( &p + 1 == &q1 ); //fail in GCC ``` The error in the second case is > error: the value of 'q1' is not usable in a constant expression > note: 'q1' was not initialized with a constant expression Online demo: https://gcc.godbolt.org/z/ja73eEG7o