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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Vincent Hamp from comment #0)
> The following snippet allows using reinterpret_casts inside a constexpr.
> 
> #include <cstdint>
> uint64_t v;
> constexpr auto p{reinterpret_cast<uint64_t>(&v) - 1u};
> 
> Compiled with GCC 10.1 and 9.3 with -std=c++2a
> 
> 
> Interestingly subtracting 0u results in an error.

Here a library-free variant of the code including the compiler flags used:

-Wall -Wextra -std=gnu++2a -pedantic 

tested using gcc 11.0.0 20200522 (experimental):

//<<<<<<<<<<<<<<<<<<<<<
using uint64_t = unsigned long;
static_assert(sizeof(uint64_t) * 8 == 64);
uint64_t v;
constexpr auto p{reinterpret_cast<uint64_t>(&v) - 1u};

int main() 
{
}
//>>>>>>>>>>>>>>>>>>>>>>>

The essential part of the reproducer is the fact that we have a variable of
static storage duration involved. Using a local variable in main() does make
the compiler reject the code.

Reply via email to