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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #13 from Martin Sebor <msebor at gcc dot gnu.org> ---
The latest C++ working draft (N4582 from March 2016) makes it clear that
reinterpret_cast cannot be evaluated in core constant expressions.  AFAICS,
this restriction hasn't changed since C++ 11.  The current top of trunk (GCC
7.0) and prior released versions still accept reinterpret_cast in constexpr
contexts, including the expression in comment #0.

In my work on bug 60760 I looked into how feasible it would be to reject
reinterpret_cast in constexpr contexts.  Rejecting examples like the one in
comment #0 is doable because a non-zero integer constant can only be converted
to a pointer by a reinterpret_cast, but rejecting others, such as

  int i
  constexpr void *p = reinterpret_cast<void*>(&i);

looks harder because the representation of this cast (a NOP_EXPR) is
indistinguishable from that of the following valid core constant expression:

  constexpr void *p = &i;

The fact that one was the result of a reinterpret_cast and another of implicit
conversion is long lost by the time it's interpreted in a constexpr context. 
To distinguish the two expressions, their internal representation would need to
be different.

Reply via email to