Skip to content

Commit

Permalink
[Sema] Don't emit multiple diags for one error
Browse files Browse the repository at this point in the history
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

llvm-svn: 250078
  • Loading branch information
gburgessiv committed Oct 12, 2015
1 parent 61e13de commit 5f2ef45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 13 additions & 5 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9911,6 +9911,7 @@ class AddressOfFunctionResolver {
bool TargetTypeIsNonStaticMemberFunction;
bool FoundNonTemplateFunction;
bool StaticMemberFunctionFromBoundPointer;
bool HasComplained;

OverloadExpr::FindResult OvlExprInfo;
OverloadExpr *OvlExpr;
Expand All @@ -9927,6 +9928,7 @@ class AddressOfFunctionResolver {
!!TargetType->getAs<MemberPointerType>()),
FoundNonTemplateFunction(false),
StaticMemberFunctionFromBoundPointer(false),
HasComplained(false),
OvlExprInfo(OverloadExpr::find(SourceExpr)),
OvlExpr(OvlExprInfo.Expression),
FailedCandidates(OvlExpr->getNameLoc()) {
Expand Down Expand Up @@ -9977,7 +9979,9 @@ class AddressOfFunctionResolver {
Matches.size() > 1)
EliminateSuboptimalCudaMatches();
}


bool hasComplained() const { return HasComplained; }

private:
bool isTargetTypeAFunction() const {
return TargetFunctionType->isFunctionType();
Expand Down Expand Up @@ -10057,8 +10061,10 @@ class AddressOfFunctionResolver {
// 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,
Expand Down Expand Up @@ -10140,7 +10146,8 @@ class AddressOfFunctionResolver {
Matches[0].first = Matches[Result - MatchesCopy.begin()].first;
Matches[0].second = cast<FunctionDecl>(*Result);
Matches.resize(1);
}
} else
HasComplained |= Complain;
}

void EliminateAllTemplateMatches() {
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 3 additions & 7 deletions clang/test/SemaCXX/addr-of-overloaded-function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,9 @@ namespace PR7971 {
}

namespace PR8033 {
template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}} \
// expected-note{{candidate function}}
template <typename T1, typename T2> 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 <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note {{candidate function [with T1 = const int, T2 = int]}}
template <typename T1, typename T2> 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 {
Expand Down

0 comments on commit 5f2ef45

Please sign in to comment.