[Bug c++/80886] __builtin_constant_p magic has broken at some point
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80886 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #3 from Jonathan Wakely --- (In reply to steveren from comment #0) > Has this behaviour changed deliberately? Yes, because the standard forbids it. As Andrew said, the __builtin_constant_p part (and what the docs say about it) is irrelevant because the (void *) 0x1000 expression is what gives an error. > As I say, it is contrary to the > Standard, but it would be disappointing to lose such a useful extension. I think it would be better to add support to C++ for "pointer literals", I've been talking with a few people about proposing that for the standard. That would allow you to create constexpr pointers from literal integers, but still disallow arbitrary reinterpret casts between them. Closing as G++ is correct to disallow this.
[Bug c++/80886] __builtin_constant_p magic has broken at some point
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80886 --- Comment #2 from Andrew Pinski --- This has nothing to do with __builtin_constant_p really. Just GCC started to rejecting: constexpr void *phardware {((void *) 0x1000)}; Starting in GCC 7; it was accepted before. What is interesting is the __builtin_constant_p makes clang accept it but that is a clang bug. >This use appears to be documented I don't think it was ever documented to be accepted this way but I could be wrong.
[Bug c++/80886] __builtin_constant_p magic has broken at some point
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80886 Jonathan Wakely changed: What|Removed |Added Known to work||6.4.0 Version|unknown |7.3.1 Known to fail||7.3.0, 8.0.1 --- Comment #1 from Jonathan Wakely --- I can't reproduce this with GCC 6, but can with GCC 7: un.cc:3:55: error: value '4096' of type 'void*' is not a constant expression constexpr void *phardware {CONST ((void *) 0x1000)}; ^ and with trunk: un.cc:3:39: error: reinterpret_cast from integer to pointer constexpr void *phardware {CONST ((void *) 0x1000)}; ^~~ un.cc:1:45: note: in definition of macro 'CONST' #define CONST(x) (__builtin_constant_p(x) ? x : x) ^