From: George Burgess IV Date: Mon, 12 Oct 2015 18:40:58 +0000 (+0000) Subject: [Sema] Don't emit multiple diags for one error X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7792ebc3c8d379d2346494c241dfc4eb4ef1c363;p=clang [Sema] Don't emit multiple diags for one error Fixed a bug where we'd emit multiple diagnostics if there was a problem taking the address of an overloaded template function. Differential Revision: http://reviews.llvm.org/D13664 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250078 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index a9259bb075..b646c85356 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -9911,6 +9911,7 @@ class AddressOfFunctionResolver { bool TargetTypeIsNonStaticMemberFunction; bool FoundNonTemplateFunction; bool StaticMemberFunctionFromBoundPointer; + bool HasComplained; OverloadExpr::FindResult OvlExprInfo; OverloadExpr *OvlExpr; @@ -9927,6 +9928,7 @@ public: !!TargetType->getAs()), FoundNonTemplateFunction(false), StaticMemberFunctionFromBoundPointer(false), + HasComplained(false), OvlExprInfo(OverloadExpr::find(SourceExpr)), OvlExpr(OvlExprInfo.Expression), FailedCandidates(OvlExpr->getNameLoc()) { @@ -9977,7 +9979,9 @@ public: Matches.size() > 1) EliminateSuboptimalCudaMatches(); } - + + bool hasComplained() const { return HasComplained; } + private: bool isTargetTypeAFunction() const { return TargetFunctionType->isFunctionType(); @@ -10057,8 +10061,10 @@ private: // now. if (S.getLangOpts().CPlusPlus14 && FunDecl->getReturnType()->isUndeducedType() && - S.DeduceReturnType(FunDecl, SourceExpr->getLocStart(), Complain)) + S.DeduceReturnType(FunDecl, SourceExpr->getLocStart(), Complain)) { + HasComplained |= Complain; return false; + } QualType ResultTy; if (Context.hasSameUnqualifiedType(TargetFunctionType, @@ -10140,7 +10146,8 @@ private: Matches[0].first = Matches[Result - MatchesCopy.begin()].first; Matches[0].second = cast(*Result); Matches.resize(1); - } + } else + HasComplained |= Complain; } void EliminateAllTemplateMatches() { @@ -10261,13 +10268,14 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, Complain); int NumMatches = Resolver.getNumMatches(); FunctionDecl *Fn = nullptr; - if (NumMatches == 0 && Complain) { + bool ShouldComplain = Complain && !Resolver.hasComplained(); + if (NumMatches == 0 && ShouldComplain) { if (Resolver.IsInvalidFormOfPointerToMemberFunction()) Resolver.ComplainIsInvalidFormOfPointerToMemberFunction(); else Resolver.ComplainNoMatchesFound(); } - else if (NumMatches > 1 && Complain) + else if (NumMatches > 1 && ShouldComplain) Resolver.ComplainMultipleMatchesFound(); else if (NumMatches == 1) { Fn = Resolver.getMatchingFunctionDecl(); diff --git a/test/SemaCXX/addr-of-overloaded-function.cpp b/test/SemaCXX/addr-of-overloaded-function.cpp index 6d05503773..09f280bc1d 100644 --- a/test/SemaCXX/addr-of-overloaded-function.cpp +++ b/test/SemaCXX/addr-of-overloaded-function.cpp @@ -125,13 +125,9 @@ namespace PR7971 { } namespace PR8033 { - template int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}} \ - // expected-note{{candidate function}} - template int f(const T1 *, T2 *); // expected-note {{candidate function [with T1 = int, T2 = const int]}} \ - // expected-note{{candidate function}} - int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} \ - // expected-error{{address of overloaded function 'f' is ambiguous}} - + template int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}} + template int f(const T1 *, T2 *); // expected-note {{candidate function [with T1 = int, T2 = const int]}} + int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} } namespace PR8196 {