Previously, if an overloaded function in a braced-init-list was encountered in
template argument deduction, and the overload set couldn't be resolved to a
particular function, we'd immediately produce a deduction failure. That's not
correct; this situation is supposed to result in that particular P/A pair being
treated as a non-deduced context, and deduction can still succeed if the type
can be deduced from elsewhere.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291014
91177308-0d34-0410-b5e6-
96231b3b80d8
"non-tautological enable_if conditions">;
def note_addrof_ovl_candidate_disabled_by_enable_if_attr : Note<
"candidate function made ineligible by enable_if">;
-def note_ovl_candidate_failed_overload_resolution : Note<
- "candidate template ignored: couldn't resolve reference to overloaded "
- "function %0">;
def note_ovl_candidate_deduced_mismatch : Note<
"candidate template ignored: deduced type "
"%diff{$ of %ordinal0 parameter does not match adjusted type $ of argument"
/// \brief The explicitly-specified template arguments were not valid
/// template arguments for the given template.
TDK_InvalidExplicitArguments,
- /// \brief The arguments included an overloaded function name that could
- /// not be resolved to a suitable function.
- TDK_FailedOverloadResolution,
/// \brief Deduction failed; that's all we know.
TDK_MiscellaneousDeductionFailure,
/// \brief CUDA Target attributes do not match.
public:
TemplateDeductionInfo(SourceLocation Loc, unsigned DeducedDepth = 0)
: Deduced(nullptr), Loc(Loc), HasSFINAEDiagnostic(false),
- DeducedDepth(DeducedDepth), Expression(nullptr) {}
+ DeducedDepth(DeducedDepth), CallArgIndex(0) {}
/// \brief Returns the location at which template argument is
/// occurring.
/// FIXME: Finish documenting this.
TemplateArgument SecondArg;
- union {
- /// \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;
-
- /// \brief The index of the function argument that caused a deduction
- /// failure.
- ///
- /// TDK_DeducedMismatch: this is the index of the argument that had a
- /// different argument type from its substituted parameter type.
- unsigned CallArgIndex;
- };
+ /// \brief The index of the function argument that caused a deduction
+ /// failure.
+ ///
+ /// TDK_DeducedMismatch: this is the index of the argument that had a
+ /// different argument type from its substituted parameter type.
+ unsigned CallArgIndex;
/// \brief Information on packs that we're currently expanding.
///
/// refers to, if any.
const TemplateArgument *getSecondArg();
- /// \brief Return the expression this deduction failure refers to,
- /// if any.
- Expr *getExpr();
-
/// \brief Return the index of the call argument that this deduction
/// failure refers to, if any.
llvm::Optional<unsigned> getCallArgIndex();
Result.HasDiagnostic = true;
}
break;
-
- case Sema::TDK_FailedOverloadResolution:
- Result.Data = Info.Expression;
- break;
}
return Result;
case Sema::TDK_TooManyArguments:
case Sema::TDK_TooFewArguments:
case Sema::TDK_InvalidExplicitArguments:
- case Sema::TDK_FailedOverloadResolution:
case Sema::TDK_CUDATargetMismatch:
break;
case Sema::TDK_SubstitutionFailure:
case Sema::TDK_DeducedMismatch:
case Sema::TDK_NonDeducedMismatch:
- case Sema::TDK_FailedOverloadResolution:
case Sema::TDK_CUDATargetMismatch:
return TemplateParameter();
case Sema::TDK_Inconsistent:
case Sema::TDK_Underqualified:
case Sema::TDK_NonDeducedMismatch:
- case Sema::TDK_FailedOverloadResolution:
case Sema::TDK_CUDATargetMismatch:
return nullptr;
case Sema::TDK_TooFewArguments:
case Sema::TDK_InvalidExplicitArguments:
case Sema::TDK_SubstitutionFailure:
- case Sema::TDK_FailedOverloadResolution:
case Sema::TDK_CUDATargetMismatch:
return nullptr;
case Sema::TDK_TooFewArguments:
case Sema::TDK_InvalidExplicitArguments:
case Sema::TDK_SubstitutionFailure:
- case Sema::TDK_FailedOverloadResolution:
case Sema::TDK_CUDATargetMismatch:
return nullptr;
return nullptr;
}
-Expr *DeductionFailureInfo::getExpr() {
- if (static_cast<Sema::TemplateDeductionResult>(Result) ==
- Sema::TDK_FailedOverloadResolution)
- return static_cast<Expr*>(Data);
-
- return nullptr;
-}
-
llvm::Optional<unsigned> DeductionFailureInfo::getCallArgIndex() {
if (static_cast<Sema::TemplateDeductionResult>(Result) ==
Sema::TDK_DeducedMismatch)
return;
}
- case Sema::TDK_FailedOverloadResolution: {
- OverloadExpr::FindResult R = OverloadExpr::find(DeductionFailure.getExpr());
- S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_failed_overload_resolution)
- << R.Expression->getName();
- return;
- }
-
case Sema::TDK_DeducedMismatch: {
// Format the template argument list into the argument string.
SmallString<128> TemplateArgString;
return 3;
case Sema::TDK_InstantiationDepth:
- case Sema::TDK_FailedOverloadResolution:
return 4;
case Sema::TDK_InvalidExplicitArguments:
// For all other cases, just match by type.
QualType ArgType = Arg->getType();
if (AdjustFunctionParmAndArgTypesForDeduction(S, TemplateParams, ParamType,
- ArgType, Arg, TDF)) {
- Info.Expression = Arg;
- return Sema::TDK_FailedOverloadResolution;
- }
+ ArgType, Arg, TDF))
+ return Sema::TDK_Success;
+
return DeduceTemplateArgumentsByTypeMatch(S, TemplateParams, ParamType,
ArgType, Info, Deduced, TDF);
}
namespace init_list_deduction_failure {
void f();
void f(int);
+ // FIXME: It'd be nice to track that 'T' became a non-deduced context due to
+ // overload resolution failure for 'f'.
template<typename T> void g(std::initializer_list<T>);
- // expected-note@-1 {{candidate template ignored: couldn't resolve reference to overloaded function 'f'}}
- void h() { g({f}); }
- // expected-error@-1 {{no matching function for call to 'g'}}
+ // expected-note@-1 {{candidate template ignored: couldn't infer template argument 'T'}}
+ void h() {
+ g({f}); // expected-error {{no matching function for call to 'g'}}
+ g({f, h}); // ok
+ }
}
namespace deleted_copy {