https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98440
Bug ID: 98440
Summary: Accepts ill-formed reinterpret_cast<int&&>(1)
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: aschepler at gmail dot com
Target Milestone: ---
g++ does not give any error or warning for a reinterpret_cast when the target
type is an rvalue reference type and the expression operand is a prvalue, for
example reinterpret_cast<int&&>(1).
In standard section [expr.reinterpret.cast], casts to reference types are
described only by paragraph 11, which allows casting a glvalue to a reference
type, but specifically says "No temporary is created". So the temporary
materialization conversion can't be implicitly used like in most expressions,
and the paragraph can't apply.
Clang++, MSVC, and ICC all produce error messages for the expression
reinterpret_cast<int&&>(1).