reinterpret_cast<int * const &>(array)

Hi, list. I came across this as an analyzer false positive, but as I read the C++ standard this is actually illegal. Can a standards expect weigh in here?

void use(int *);
void test() {
int x[8];
use(reinterpret_cast<int * const &>(x));
}

Here’s the relevant portion of the standard, [expr.reinterpret.cast]p1:

The result of the expression reinterpret_cast(v) is the result of converting the expression v to type T. If T is an lvalue reference type or an rvalue reference to function type, the result is an lvalue; if T is an rvalue reference to object type, the result is an xvalue; otherwise, the result is a prvalue and the lvalue-to- rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are performed on the expression v. Conversions that can be performed explicitly using reinterpret_cast are listed below. No other conversion can be performed explicitly using reinterpret_cast.

As I read this, the standard conversions only apply to the prvalue case, and the lvalue reference target type means this is the lvalue case. Does that seem right?

If so, I’ll go file a PR. Thanks!
Jordan

"reinterpret_cast<int * const &>(x)" is roughly equivalent to
"*reinterpret_cast<int * const *>(&x)". So test() is semantically
well-formed; it just has undefined behavior.

-Eli