[cfe-commits] r84763 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp lib/Sema/SemaTemplate.cpp test/CodeGenCXX/address-of-fntemplate.cpp

Douglas Gregor dgregor at apple.com
Wed Oct 21 14:13:38 PDT 2009


On Oct 21, 2009, at 10:16 AM, Anders Carlsson wrote:

> Author: andersca
> Date: Wed Oct 21 12:16:23 2009
> New Revision: 84763
>
> URL: http://llvm.org/viewvc/llvm-project?rev=84763&view=rev
> Log:
> Change FixOverloadedFunctionReference to return a (possibly new)  
> expression. Substitute TemplateIdRefExprs with DeclRefExprs. Doug,  
> plz review :)
>
> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Oct 21 12:16:23 2009
> @@ -5368,13 +5368,12 @@
> /// a C++ overloaded function (possibly with some parentheses and
> /// perhaps a '&' around it). We have resolved the overloaded function
> /// to the function declaration Fn, so patch up the expression E to
> -/// refer (possibly indirectly) to Fn.
> -/// Returns true if the function reference used an explicit address- 
> of operator.
> -bool Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl  
> *Fn) {
> +/// refer (possibly indirectly) to Fn. Returns the new expr.
> +Expr *Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl  
> *Fn) {
>   if (ParenExpr *PE = dyn_cast<ParenExpr>(E)) {
> -    bool ret = FixOverloadedFunctionReference(PE->getSubExpr(), Fn);
> -    E->setType(PE->getSubExpr()->getType());
> -    return ret;
> +    Expr *NewExpr = FixOverloadedFunctionReference(PE->getSubExpr 
> (), Fn);
> +    NewExpr->setType(PE->getSubExpr()->getType());
> +    return NewExpr;

This isn't quite right. We need to replace PE's subexpression with the  
result of FixOVerloadedFunctionReference, then fix the type of PE to  
reflect the type of its new subexpression.

>   } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) {
>     assert(UnOp->getOpcode() == UnaryOperator::AddrOf &&
>            "Can only take the address of an overloaded function");
> @@ -5393,12 +5392,14 @@
>           = Context.getTypeDeclType(cast<RecordDecl>(Method- 
> >getDeclContext()));
>         E->setType(Context.getMemberPointerType(Fn->getType(),
>                                                 ClassType.getTypePtr 
> ()));
> -        return true;
> +        return E;
>       }
>     }
> -    FixOverloadedFunctionReference(UnOp->getSubExpr(), Fn);
> -    E->setType(Context.getPointerType(UnOp->getSubExpr()->getType 
> ()));
> -    return true;
> +    Expr *NewExpr = FixOverloadedFunctionReference(UnOp->getSubExpr 
> (), Fn);
> +    UnOp->setSubExpr(NewExpr);
> +    UnOp->setType(Context.getPointerType(NewExpr->getType()));
> +
> +    return UnOp;
>   } else if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E)) {
>     assert((isa<OverloadedFunctionDecl>(DR->getDecl()) ||
>             isa<FunctionTemplateDecl>(DR->getDecl())) &&
> @@ -5408,10 +5409,17 @@
>   } else if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(E)) {
>     MemExpr->setMemberDecl(Fn);
>     E->setType(Fn->getType());
> +  } else if (TemplateIdRefExpr *TID = dyn_cast<TemplateIdRefExpr> 
> (E)) {
> +    // FIXME: Should we create QualifiedDeclRefExprs here too?
> +    // FIXME: We should capture the template arguments here.
> +    E = new (Context) DeclRefExpr(Fn, Fn->getType(),
> +                                  TID->getSourceRange().getBegin());
> +    TID->Destroy(Context);

We should be building QualifiedDeclRefExprs when the TemplateIdRefExpr  
refers to a qualified name. Capturing the template arguments would, of  
course, be wonderful :)

   - Doug




More information about the cfe-commits mailing list