https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92411
Bug ID: 92411
Summary: conformance issue with reinterpret_cast in constant
expressions
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Darrell.Wright at gmail dot com
Target Milestone: ---
It looks like there is a regression in trunk(20171107 on CE) that allows
reinterpret_casts in constant expressions.
https://gcc.godbolt.org/z/m7Qytn
using size_t = decltype(sizeof(int));
constexpr char const * func( char const * ptr ) {
return reinterpret_cast<char const *>( ptr );
}
static_assert( func( nullptr ) == nullptr );
template<size_t N>
constexpr char const * func2( char const (&s)[N] ) {
return reinterpret_cast<char const *>( s );
}
static_assert( *func2( "Hello" ) == 'H' );
I think this should be ill formed with a diag according to the following links,
but it is allowed
https://eel.is/c++draft/expr.const#4.15
https://eel.is/c++draft/dcl.pre#6