https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118256
Bug ID: 118256 Summary: gcc fails to match the function parameter list when a reinterpret_cast with rvalue reference is involved Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rush102333 at gmail dot com Target Milestone: --- The following code should be valid, despite the reinterpret_cast here actually does not cast anything: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ constexpr void foo (int&& i) { i = 0; } void bar(int&& i) { foo(reinterpret_cast<int&&>(i)); } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCC rejects it with the following diagnostic: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>: In function 'void bar(int&&)': <source>:5:7: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int' 5 | foo(reinterpret_cast<int&&>(i)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:1:27: note: initializing argument 1 of 'constexpr void foo(int&&)' 1 | constexpr void foo (int&& i) { i = 0; } | ~~~~~~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It's quite interesting that changing the type of 'i' from 'int&&' to 'int'(which makes the reinterpret_cast effective) can make the code successfully compile. MSVC, EDG and clang accept the code. See https://godbolt.org/z/h5faP31fe