diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-11-08 15:20:28 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-11-08 15:20:28 +0000 |
| commit | bcd625305b2d97f1684ce6597e20959e9eb00879 (patch) | |
| tree | 5d24f3514268a874832b92b02b34775ed07f6710 /clang | |
| parent | c5688628d89cdcffd9b901bebaa795e2ffddc11f (diff) | |
| download | bcm5719-llvm-bcd625305b2d97f1684ce6597e20959e9eb00879.tar.gz bcm5719-llvm-bcd625305b2d97f1684ce6597e20959e9eb00879.zip | |
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.
llvm-svn: 118407
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 23 | ||||
| -rw-r--r-- | clang/test/SemaCXX/addr-of-overloaded-function.cpp | 29 |
2 files changed, 42 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index bee2ba46a87..f45893df86d 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/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/clang/test/SemaCXX/addr-of-overloaded-function.cpp b/clang/test/SemaCXX/addr-of-overloaded-function.cpp index c095e946c8b..00d91043e4e 100644 --- a/clang/test/SemaCXX/addr-of-overloaded-function.cpp +++ b/clang/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<typename T> + void foo() + { + } + + struct B + { + template<typename T> + B(const T&) + { + } + }; + + void bar(const B& b) + { + } + + void bar2(const B& b = foo<int>) + { + } + + void test(int argc, char** argv) + { + bar(foo<int>); + bar2(); + } +} |

