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

Anders Carlsson andersca at mac.com
Tue Oct 20 16:18:27 PDT 2009


On Oct 17, 2009, at 1:50 PM, Sebastian Redl wrote:

> Author: cornedbee
> Date: Sat Oct 17 15:50:27 2009
> New Revision: 84362
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=84362&view=rev
> Log:
> Don't add implicit casts of explicit address-taking of overloaded functions.
> 
> Taking the address of an overloaded function with an explicit address-of operator wrapped the operator in an implicit cast that added yet another pointer level, leaving us with a corrupted AST, which crashed CodeGen in the test case I've added. Fix this by making FixOverloadedFunctionReference return whether there was an address-of operator and not adding the implicit cast in that case.

Hi Sebastian,

is there a reason why we can't just check the ExprType and not cast if it's already a pointer or pointer-to-member-function type? Something like

Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp	(revision 84685)
+++ lib/Sema/SemaExprCXX.cpp	(working copy)
@@ -1226,12 +1226,13 @@
       if (DiagnoseUseOfDecl(Fn, From->getSourceRange().getBegin()))
         return true;
 
-      bool WasAddrOf = FixOverloadedFunctionReference(From, Fn);
+      FixOverloadedFunctionReference(From, Fn);
       FromType = From->getType();
+        
       // If there's already an address-of operator in the expression, we have
       // the right type already, and the code below would just introduce an
       // invalid additional pointer level.
-      if (WasAddrOf)
+      if (FromType->isPointerType() || FromType->isMemberFunctionPointerType())
         break;
     }
     FromType = Context.getPointerType(FromType);

The reason I'm asking is that I want to change FixOverloadedFunctionReference to return a (possibly new) expr, instead of returning this boolean.

Anders




More information about the cfe-commits mailing list