Skip to content

Instantly share code, notes, and snippets.

@pfultz2
Last active January 2, 2016 23:29
Show Gist options
  • Save pfultz2/8376525 to your computer and use it in GitHub Desktop.
Save pfultz2/8376525 to your computer and use it in GitHub Desktop.
13309 Patch for clang 3.4. This will improve the backtrace for sfinae errors.
diff --git a/tools/clang/include/clang/Sema/TemplateDeduction.h b/tools/clang/include/clang/Sema/TemplateDeduction.h
index 1daa689..793a50a 100644
--- a/tools/clang/include/clang/Sema/TemplateDeduction.h
+++ b/tools/clang/include/clang/Sema/TemplateDeduction.h
@@ -36,6 +36,9 @@ class TemplateDeductionInfo {
/// deduction is occurring.
SourceLocation Loc;
+ /// \brief Should we suppress errors during substitution?
+ bool IsSFINAEContext;
+
/// \brief Have we suppressed an error during deduction?
bool HasSFINAEDiagnostic;
@@ -48,7 +51,8 @@ class TemplateDeductionInfo {
public:
TemplateDeductionInfo(SourceLocation Loc)
- : Deduced(0), Loc(Loc), HasSFINAEDiagnostic(false), Expression(0) { }
+ : Deduced(0), Loc(Loc), IsSFINAEContext(true), HasSFINAEDiagnostic(false),
+ Expression(0) { }
/// \brief Returns the location at which template argument is
/// occurring.
@@ -78,6 +82,10 @@ public:
Deduced = NewDeduced;
}
+ /// \brief Should we suppress errors during this deduction?
+ bool isSFINAEContext() const { return IsSFINAEContext; }
+ void setSFINAEContext(bool SFINAE) { IsSFINAEContext = SFINAE; }
+
/// \brief Is a SFINAE diagnostic available?
bool hasSFINAEDiagnostic() const {
return HasSFINAEDiagnostic;
diff --git a/tools/clang/lib/Sema/SemaOverload.cpp b/tools/clang/lib/Sema/SemaOverload.cpp
index 802f2b7..0f627a7 100644
--- a/tools/clang/lib/Sema/SemaOverload.cpp
+++ b/tools/clang/lib/Sema/SemaOverload.cpp
@@ -10335,6 +10335,29 @@ static ExprResult FinishOverloadedCallExpr(Sema &SemaRef, Scope *S, Expr *Fn,
if (!Recovery.isInvalid())
return Recovery;
+ // Produce the diagnostics for every substitution failure
+ for(OverloadCandidateSet::iterator Cand = CandidateSet->begin();
+ Cand != CandidateSet->end();Cand++) {
+ if (Cand->DeductionFailure.Result == Sema::TDK_SubstitutionFailure) {
+ TemplateDeductionInfo Info(CandidateSet->getLocation());
+ Info.setSFINAEContext(false);
+ FunctionDecl *Specialization = 0;
+ TemplateArgumentListInfo TemplateArgStorage, *ExplicitTemplateArgs = 0;
+ if (ULE->hasExplicitTemplateArgs()) {
+ ULE->getExplicitTemplateArgs().copyInto(TemplateArgStorage);
+ ExplicitTemplateArgs = &TemplateArgStorage;
+ }
+ Sema::TemplateDeductionResult Result =
+ SemaRef.DeduceTemplateArguments(Cand->Function->getDescribedFunctionTemplate(),
+ ExplicitTemplateArgs,
+ Args,
+ Specialization, Info);
+ assert(Result && "template deduction didn't fail on retry");
+ if (Result)
+ continue;
+ }
+ }
+
SemaRef.Diag(Fn->getLocStart(),
diag::err_ovl_no_viable_function_in_call)
<< ULE->getName() << Fn->getSourceRange();
diff --git a/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp b/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 8904f37..c280cbc 100644
--- a/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -706,7 +706,8 @@ Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const {
// We're either substitution explicitly-specified template arguments
// or deduced template arguments, so SFINAE applies.
assert(Active->DeductionInfo && "Missing deduction info pointer");
- return Active->DeductionInfo;
+ if (Active->DeductionInfo->isSFINAEContext())
+ return Active->DeductionInfo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment