From: Douglas Gregor Date: Mon, 8 Nov 2010 15:20:28 +0000 (+0000) Subject: When attempting reference binding to an overloaded function, also X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3afb97700200f629d6036e437267af9c1fd37c90;p=clang When attempting reference binding to an overloaded function, also consider that we might be trying to bind a reference to a class type, which involves a constructor call. Fixes PR7425. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118407 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index bee2ba46a8..f45893df86 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -2511,18 +2511,17 @@ static void TryReferenceInitialization(Sema &S, // type of the resulting function. if (S.Context.getCanonicalType(T2) == S.Context.OverloadTy) { DeclAccessPair Found; - FunctionDecl *Fn = S.ResolveAddressOfOverloadedFunction(Initializer, - T1, - false, - Found); - if (!Fn) { + if (FunctionDecl *Fn = S.ResolveAddressOfOverloadedFunction(Initializer, + T1, + false, + Found)) { + Sequence.AddAddressOverloadResolutionStep(Fn, Found); + cv2T2 = Fn->getType(); + T2 = cv2T2.getUnqualifiedType(); + } else if (!T1->isRecordType()) { Sequence.SetFailed(InitializationSequence::FK_AddressOfOverloadFailed); return; } - - Sequence.AddAddressOverloadResolutionStep(Fn, Found); - cv2T2 = Fn->getType(); - T2 = cv2T2.getUnqualifiedType(); } // Compute some basic properties of the types and the initializer. @@ -2604,7 +2603,9 @@ static void TryReferenceInitialization(Sema &S, // We handled the function type stuff above. if (!((isLValueRef && T1Quals.hasConst() && !T1Quals.hasVolatile()) || (isRValueRef && InitCategory.isRValue()))) { - if (ConvOvlResult && !Sequence.getFailedCandidateSet().empty()) + if (S.Context.getCanonicalType(T2) == S.Context.OverloadTy) + Sequence.SetFailed(InitializationSequence::FK_AddressOfOverloadFailed); + else if (ConvOvlResult && !Sequence.getFailedCandidateSet().empty()) Sequence.SetOverloadFailure( InitializationSequence::FK_ReferenceInitOverloadFailed, ConvOvlResult); @@ -2706,6 +2707,8 @@ static void TryReferenceInitialization(Sema &S, Sequence.SetOverloadFailure( InitializationSequence::FK_ReferenceInitOverloadFailed, ConvOvlResult); + else if (S.Context.getCanonicalType(T2) == S.Context.OverloadTy) + Sequence.SetFailed(InitializationSequence::FK_AddressOfOverloadFailed); else Sequence.SetFailed(InitializationSequence::FK_ReferenceInitFailed); return; diff --git a/test/SemaCXX/addr-of-overloaded-function.cpp b/test/SemaCXX/addr-of-overloaded-function.cpp index c095e946c8..00d91043e4 100644 --- a/test/SemaCXX/addr-of-overloaded-function.cpp +++ b/test/SemaCXX/addr-of-overloaded-function.cpp @@ -116,3 +116,32 @@ namespace PR8196 { add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}} } } + +namespace PR7425 { + template + void foo() + { + } + + struct B + { + template + B(const T&) + { + } + }; + + void bar(const B& b) + { + } + + void bar2(const B& b = foo) + { + } + + void test(int argc, char** argv) + { + bar(foo); + bar2(); + } +}