Subject: [std-proposals] Allow reinterpret_cast (and static_cast from void*) in a constant expression in limited cases
From: connor horman (chorman64_at_[hidden])
Date: 2019-10-31 09:14:06
I propose to allow reinterpret_cast from pointer to integral, as well as
the no-op/identity reintepret_cast in constant expressions. This particular
version is useful in implementing hashcode algorithms at compile time, and
to my knowledge bit_cast does not work for pointer types at compile time.
As an extension to this, I propose to allow static_cast from cv void* if
and only if the object pointed to by the argument to the static_cast is
pointer-interconvertible with an object of target type (with the exception
of identity static_cast to cv void*, which should always be valid). This
would naturally extend to allowing reintepret_cast between object pointer
types if and only if the static_cast from cv void* to the destination type
would be valid by these rules. The static_cast would result in a pointer to
the object of the destination type which is pointer-interconvertible with
the original pointer.
The results would be valid integral and pointer constant expressions
respectively, dereferencing the pointer would result in an lvalue constant
expression and can undergo lvalue-to-rvalue conversion in a core constant
expression if an lvalue of pointer-interconvertible object could undergo
lvalue-to-rvalue conversion in a core constant expression.
STD-PROPOSALS list run by email@example.com
Standard Proposals Archives on Google Groups