From 980fb16f9a05f946007cd65929bd611d8812d8cd Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 29 Apr 2010 18:24:40 +0000 Subject: When determining a standard conversion sequence involves resolving the address of an overloaded function (or function template), perform that resolution prior to determining the implicit conversion sequence. This resolution is not part of the implicit conversion sequence itself. Previously, we would always consider this resolution to be a function pointer decay, which was a lie: there might be an explicit & in the expression, in which case decay should not occur. This caused the CodeGen assertion in PR6973 (where we created a pointer to a pointer to a function when we should have had a pointer to a function), but it's likely that there are corner cases of overload resolution where this would have failed. Cleaned up the code involved in determining the type that will produced afer resolving the overloaded function reference, and added an assertion to make sure the result is correct. Fixes PR6973. llvm-svn: 102650 --- clang/lib/Sema/SemaExprCXX.cpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'clang/lib/Sema/SemaExprCXX.cpp') diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 7c324235ca8..60ced725e90 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1660,6 +1660,21 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, return false; } + // Resolve overloaded function references. + if (Context.hasSameType(FromType, Context.OverloadTy)) { + DeclAccessPair Found; + FunctionDecl *Fn = ResolveAddressOfOverloadedFunction(From, ToType, + true, Found); + if (!Fn) + return true; + + if (DiagnoseUseOfDecl(Fn, From->getSourceRange().getBegin())) + return true; + + From = FixOverloadedFunctionReference(From, Found, Fn); + FromType = From->getType(); + } + // Perform the first implicit conversion. switch (SCS.First) { case ICK_Identity: @@ -1673,25 +1688,6 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, break; case ICK_Function_To_Pointer: - if (Context.getCanonicalType(FromType) == Context.OverloadTy) { - DeclAccessPair Found; - FunctionDecl *Fn = ResolveAddressOfOverloadedFunction(From, ToType, - true, Found); - if (!Fn) - return true; - - if (DiagnoseUseOfDecl(Fn, From->getSourceRange().getBegin())) - return true; - - From = FixOverloadedFunctionReference(From, Found, 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 (FromType->isPointerType() || FromType->isMemberFunctionPointerType()) - break; - } FromType = Context.getPointerType(FromType); ImpCastExprToType(From, FromType, CastExpr::CK_FunctionToPointerDecay); break; -- cgit v1.2.3