[cfe-dev] Fixes for References
Bill Wendling
isanbard at gmail.com
Sun Jul 15 23:43:15 PDT 2007
On Jul 15, 2007, at 10:48 PM, Chris Lattner wrote:
>>> This is logically independent from the rest of the patch. I'd
>>> like to eventually remove the return value of
>>> DefaultFunctionArrayConversion, so please remove this piece.
>>
>> That would break the references stuff. The "stripping of the
>> references" is why I made this change. Otherwise, we get a
>> reference type from
>>
>> QualType LHSTy = LHSExp->getType(), RHSTy = RHSExp->getType();
>>
>> And it fails below. If you're going to remove the return value of
>> DefaultFunctionArrayConversion, then we'd have to do yet another
>> stripping of the reference afterwards.
>
> That's the problem: after calling DefaultFunctionArrayConversion,
> the expr returned should have its reference stripped off with an
> implicit conversion.
>
> One invariant is that the type (current) returned by
> DefaultFunctionArrayConversion should always be the type of the expr.
>
Then that makes my patch even simpler. Here's the relevant part:
Index: Sema/SemaExpr.cpp
===================================================================
--- Sema/SemaExpr.cpp (revision 39902)
+++ Sema/SemaExpr.cpp (working copy)
@@ -579,7 +579,9 @@
QualType Sema::DefaultFunctionArrayConversion(Expr *&e) {
QualType t = e->getType();
assert(!t.isNull() && "DefaultFunctionArrayConversion - missing
type");
-
+
+ if (const ReferenceType *ref = dyn_cast<ReferenceType>
(t.getCanonicalType()))
+ t = promoteExprToType(e, ref->getReferenceeType()); // C++ 5p6
if (t->isFunctionType())
return promoteExprToType(e, Context.getPointerType(t));
if (const ArrayType *ary = dyn_cast<ArrayType>(t.getCanonicalType
()))
@@ -596,6 +598,8 @@
QualType t = expr->getType();
assert(!t.isNull() && "UsualUnaryConversions - missing type");
+ if (const ReferenceType *ref = dyn_cast<ReferenceType>
(t.getCanonicalType()))
+ t = promoteExprToType(expr, ref->getReferenceeType()); // C++ 5p6
if (t->isPromotableIntegerType()) // C99 6.3.1.1p2
return promoteExprToType(expr, Context.IntTy);
return DefaultFunctionArrayConversion(expr);
Okay? :-)
-bw
More information about the cfe-dev
mailing list