GCC produces warning when compiling the following code:
void* const & cast(int* const &ptr)
{
return static_cast<void* const &>(ptr);
}
The warning is "returning reference to temporary" (coliru).
Clang compiles the code without warnings (coliru).
Which compiler is right? And why is reference converted to temporary?
Also note that changing static_cast
to reinterpret_cast
fixes the warning (coliru).