GCC converts reference to temporary when doing static_cast to void pointer reference

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).



from Recent Questions - Stack Overflow https://ift.tt/3qp7ezw
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)