[cfe-dev] Patch for References
Chris Lattner
clattner at apple.com
Thu Jul 12 22:29:00 PDT 2007
On Jul 12, 2007, at 10:04 PM, Bill Wendling wrote:
> Hi all,
>
> Here's a patch to correct some reference problems. We weren't
> accounting for references to functions and references to arrays. So
> something like this would produce errors:
>
> int g(int);
>
> void f() {
> int (&rg)(int) = g;
> rg(i); // Error
>
> int a[3];
> int (&ra)[3] = a;
> ra[1] = i; // Error
> }
>
> Okay to commit?
+ if (isa<ReferenceType>(TR.getCanonicalType())) // C++ 3.10p5
references
+ return LV_Valid;
This citation doesn't make sense, it's talking about function
results, not references in general.
+ } else if (isa<ReferenceType>(canonT1)) {
+ // C++ 8.5.3p1: A reference to an array.
+ baseType = canonT1;
+ indexType = canonT2;
+ baseExpr = static_cast<Expr *>(Base);
+ indexExpr = static_cast<Expr *>(Idx);
+ } else if (isa<ReferenceType>(canonT2)) { // uncommon
+ // C++ 8.5.3p1: A reference to an array.
+ baseType = canonT2;
+ indexType = canonT1;
+ baseExpr = static_cast<Expr *>(Idx);
+ indexExpr = static_cast<Expr *>(Base);
This doesn't make sense to me. Wouldn't it be incorrect for:
int *Q;
int *&P = Q;
P[1];
?
-Chris
More information about the cfe-dev
mailing list