[cfe-dev] reinterpret_cast<int * const &>(array)

Jordan Rose jordan_rose at apple.com
Mon Jun 11 15:05:00 PDT 2012


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<T>(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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120611/d4a625f5/attachment.html>


More information about the cfe-dev mailing list