r174036 - Replace "failed template argument deduction" diagnostic with something useful
Richard Smith
richard-llvm at metafoo.co.uk
Wed Jan 30 20:03:12 PST 2013
Author: rsmith
Date: Wed Jan 30 22:03:12 2013
New Revision: 174036
URL: http://llvm.org/viewvc/llvm-project?rev=174036&view=rev
Log:
Replace "failed template argument deduction" diagnostic with something useful
in the one case where we've already factored out a reason code.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Overload.h
cfe/trunk/include/clang/Sema/TemplateDeduction.h
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=174036&r1=174035&r2=174036&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jan 30 22:03:12 2013
@@ -2331,6 +2331,9 @@ def note_ovl_candidate_substitution_fail
"candidate template ignored: substitution failure%0%1">;
def note_ovl_candidate_disabled_by_enable_if : Note<
"candidate template ignored: disabled by %0%1">;
+def note_ovl_candidate_failed_overload_resolution : Note<
+ "candidate template ignored: couldn't resolve reference to overloaded "
+ "function %0">;
// Note that we don't treat templates differently for this diagnostic.
def note_ovl_candidate_arity : Note<"candidate "
Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=174036&r1=174035&r2=174036&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Wed Jan 30 22:03:12 2013
@@ -694,6 +694,10 @@ namespace clang {
/// \brief Return the second template argument this deduction failure
/// refers to, if any.
const TemplateArgument *getSecondArg();
+
+ /// \brief Return the expression this deduction failure refers to,
+ /// if any.
+ Expr *getExpr();
/// \brief Free any memory associated with this deduction failure.
void Destroy();
Modified: cfe/trunk/include/clang/Sema/TemplateDeduction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/TemplateDeduction.h?rev=174036&r1=174035&r2=174036&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/TemplateDeduction.h (original)
+++ cfe/trunk/include/clang/Sema/TemplateDeduction.h Wed Jan 30 22:03:12 2013
@@ -47,7 +47,7 @@ class TemplateDeductionInfo {
public:
TemplateDeductionInfo(SourceLocation Loc)
- : Deduced(0), Loc(Loc), HasSFINAEDiagnostic(false) { }
+ : Deduced(0), Loc(Loc), HasSFINAEDiagnostic(false), Expression(0) { }
/// \brief Returns the location at which template argument is
/// occurring.
@@ -150,6 +150,13 @@ public:
///
/// FIXME: Finish documenting this.
TemplateArgument SecondArg;
+
+ /// \brief The expression which caused a deduction failure.
+ ///
+ /// TDK_FailedOverloadResolution: this argument is the reference to
+ // an overloaded function which could not be resolved to a specific
+ // function.
+ Expr *Expression;
};
}
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=174036&r1=174035&r2=174036&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Jan 30 22:03:12 2013
@@ -588,8 +588,11 @@ static MakeDeductionFailureInfo(ASTConte
}
break;
- case Sema::TDK_NonDeducedMismatch:
case Sema::TDK_FailedOverloadResolution:
+ Result.Data = Info.Expression;
+ break;
+
+ case Sema::TDK_NonDeducedMismatch:
break;
}
@@ -741,6 +744,15 @@ OverloadCandidate::DeductionFailureInfo:
return 0;
}
+Expr *
+OverloadCandidate::DeductionFailureInfo::getExpr() {
+ if (static_cast<Sema::TemplateDeductionResult>(Result) ==
+ Sema::TDK_FailedOverloadResolution)
+ return static_cast<Expr*>(Data);
+
+ return 0;
+}
+
void OverloadCandidateSet::destroyCandidates() {
for (iterator i = begin(), e = end(); i != e; ++i) {
for (unsigned ii = 0, ie = i->NumConversions; ii != ie; ++ii)
@@ -8442,10 +8454,18 @@ void DiagnoseBadDeduction(Sema &S, Overl
return;
}
+ case Sema::TDK_FailedOverloadResolution: {
+ OverloadExpr::FindResult R =
+ OverloadExpr::find(Cand->DeductionFailure.getExpr());
+ S.Diag(Fn->getLocation(),
+ diag::note_ovl_candidate_failed_overload_resolution)
+ << R.Expression->getName();
+ return;
+ }
+
// TODO: diagnose these individually, then kill off
// note_ovl_candidate_bad_deduction, which is uselessly vague.
case Sema::TDK_NonDeducedMismatch:
- case Sema::TDK_FailedOverloadResolution:
S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_deduction);
MaybeEmitInheritedConstructorNote(S, Fn);
return;
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=174036&r1=174035&r2=174036&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Jan 30 22:03:12 2013
@@ -2879,7 +2879,8 @@ ResolveOverloadForDeduction(Sema &S, Tem
/// described in C++ [temp.deduct.call].
///
/// \returns true if the caller should not attempt to perform any template
-/// argument deduction based on this P/A pair.
+/// argument deduction based on this P/A pair because the argument is an
+/// overloaded function set that could not be resolved.
static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S,
TemplateParameterList *TemplateParams,
QualType &ParamType,
@@ -2895,7 +2896,7 @@ static bool AdjustFunctionParmAndArgType
if (ParamRefType) {
QualType PointeeType = ParamRefType->getPointeeType();
- // If the argument has incomplete array type, try to complete it's type.
+ // If the argument has incomplete array type, try to complete its type.
if (ArgType->isIncompleteArrayType() && !S.RequireCompleteExprType(Arg, 0))
ArgType = Arg->getType();
@@ -2993,8 +2994,8 @@ static bool hasDeducibleTemplateParamete
/// \brief Perform template argument deduction by matching a parameter type
/// against a single expression, where the expression is an element of
-/// an initializer list that was originally matched against the argument
-/// type.
+/// an initializer list that was originally matched against a parameter
+/// of type \c initializer_list\<ParamType\>.
static Sema::TemplateDeductionResult
DeduceTemplateArgumentByListElement(Sema &S,
TemplateParameterList *TemplateParams,
@@ -3023,8 +3024,10 @@ DeduceTemplateArgumentByListElement(Sema
// For all other cases, just match by type.
QualType ArgType = Arg->getType();
if (AdjustFunctionParmAndArgTypesForDeduction(S, TemplateParams, ParamType,
- ArgType, Arg, TDF))
+ ArgType, Arg, TDF)) {
+ Info.Expression = Arg;
return Sema::TDK_FailedOverloadResolution;
+ }
return DeduceTemplateArgumentsByTypeMatch(S, TemplateParams, ParamType,
ArgType, Info, Deduced, TDF);
}
Modified: cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp?rev=174036&r1=174035&r2=174036&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp Wed Jan 30 22:03:12 2013
@@ -199,3 +199,12 @@ namespace initlist_of_array {
f({{1,2},{3,4}});
}
}
+
+namespace init_list_deduction_failure {
+ void f();
+ void f(int);
+ template<typename T> void g(std::initializer_list<T>);
+ // expected-note at -1 {{candidate template ignored: couldn't resolve reference to overloaded function 'f'}}
+ void h() { g({f}); }
+ // expected-error at -1 {{no matching function for call to 'g'}}
+}
More information about the cfe-commits
mailing list