Skip to content

Commit 363ae81

Browse files
committed
Fix failure to treat overloaded function in braced-init-list as a non-deduced context.
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. llvm-svn: 291014
1 parent e950602 commit 363ae81

File tree

6 files changed

+17
-59
lines changed

6 files changed

+17
-59
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,9 +3375,6 @@ def err_addrof_function_disabled_by_enable_if_attr : Error<
33753375
"non-tautological enable_if conditions">;
33763376
def note_addrof_ovl_candidate_disabled_by_enable_if_attr : Note<
33773377
"candidate function made ineligible by enable_if">;
3378-
def note_ovl_candidate_failed_overload_resolution : Note<
3379-
"candidate template ignored: couldn't resolve reference to overloaded "
3380-
"function %0">;
33813378
def note_ovl_candidate_deduced_mismatch : Note<
33823379
"candidate template ignored: deduced type "
33833380
"%diff{$ of %ordinal0 parameter does not match adjusted type $ of argument"

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6576,9 +6576,6 @@ class Sema {
65766576
/// \brief The explicitly-specified template arguments were not valid
65776577
/// template arguments for the given template.
65786578
TDK_InvalidExplicitArguments,
6579-
/// \brief The arguments included an overloaded function name that could
6580-
/// not be resolved to a suitable function.
6581-
TDK_FailedOverloadResolution,
65826579
/// \brief Deduction failed; that's all we know.
65836580
TDK_MiscellaneousDeductionFailure,
65846581
/// \brief CUDA Target attributes do not match.

clang/include/clang/Sema/TemplateDeduction.h

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TemplateDeductionInfo {
5353
public:
5454
TemplateDeductionInfo(SourceLocation Loc, unsigned DeducedDepth = 0)
5555
: Deduced(nullptr), Loc(Loc), HasSFINAEDiagnostic(false),
56-
DeducedDepth(DeducedDepth), Expression(nullptr) {}
56+
DeducedDepth(DeducedDepth), CallArgIndex(0) {}
5757

5858
/// \brief Returns the location at which template argument is
5959
/// occurring.
@@ -175,21 +175,12 @@ class TemplateDeductionInfo {
175175
/// FIXME: Finish documenting this.
176176
TemplateArgument SecondArg;
177177

178-
union {
179-
/// \brief The expression which caused a deduction failure.
180-
///
181-
/// TDK_FailedOverloadResolution: this argument is the reference to
182-
/// an overloaded function which could not be resolved to a specific
183-
/// function.
184-
Expr *Expression;
185-
186-
/// \brief The index of the function argument that caused a deduction
187-
/// failure.
188-
///
189-
/// TDK_DeducedMismatch: this is the index of the argument that had a
190-
/// different argument type from its substituted parameter type.
191-
unsigned CallArgIndex;
192-
};
178+
/// \brief The index of the function argument that caused a deduction
179+
/// failure.
180+
///
181+
/// TDK_DeducedMismatch: this is the index of the argument that had a
182+
/// different argument type from its substituted parameter type.
183+
unsigned CallArgIndex;
193184

194185
/// \brief Information on packs that we're currently expanding.
195186
///
@@ -235,10 +226,6 @@ struct DeductionFailureInfo {
235226
/// refers to, if any.
236227
const TemplateArgument *getSecondArg();
237228

238-
/// \brief Return the expression this deduction failure refers to,
239-
/// if any.
240-
Expr *getExpr();
241-
242229
/// \brief Return the index of the call argument that this deduction
243230
/// failure refers to, if any.
244231
llvm::Optional<unsigned> getCallArgIndex();

clang/lib/Sema/SemaOverload.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -644,10 +644,6 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
644644
Result.HasDiagnostic = true;
645645
}
646646
break;
647-
648-
case Sema::TDK_FailedOverloadResolution:
649-
Result.Data = Info.Expression;
650-
break;
651647
}
652648

653649
return Result;
@@ -662,7 +658,6 @@ void DeductionFailureInfo::Destroy() {
662658
case Sema::TDK_TooManyArguments:
663659
case Sema::TDK_TooFewArguments:
664660
case Sema::TDK_InvalidExplicitArguments:
665-
case Sema::TDK_FailedOverloadResolution:
666661
case Sema::TDK_CUDATargetMismatch:
667662
break;
668663

@@ -705,7 +700,6 @@ TemplateParameter DeductionFailureInfo::getTemplateParameter() {
705700
case Sema::TDK_SubstitutionFailure:
706701
case Sema::TDK_DeducedMismatch:
707702
case Sema::TDK_NonDeducedMismatch:
708-
case Sema::TDK_FailedOverloadResolution:
709703
case Sema::TDK_CUDATargetMismatch:
710704
return TemplateParameter();
711705

@@ -737,7 +731,6 @@ TemplateArgumentList *DeductionFailureInfo::getTemplateArgumentList() {
737731
case Sema::TDK_Inconsistent:
738732
case Sema::TDK_Underqualified:
739733
case Sema::TDK_NonDeducedMismatch:
740-
case Sema::TDK_FailedOverloadResolution:
741734
case Sema::TDK_CUDATargetMismatch:
742735
return nullptr;
743736

@@ -765,7 +758,6 @@ const TemplateArgument *DeductionFailureInfo::getFirstArg() {
765758
case Sema::TDK_TooFewArguments:
766759
case Sema::TDK_InvalidExplicitArguments:
767760
case Sema::TDK_SubstitutionFailure:
768-
case Sema::TDK_FailedOverloadResolution:
769761
case Sema::TDK_CUDATargetMismatch:
770762
return nullptr;
771763

@@ -793,7 +785,6 @@ const TemplateArgument *DeductionFailureInfo::getSecondArg() {
793785
case Sema::TDK_TooFewArguments:
794786
case Sema::TDK_InvalidExplicitArguments:
795787
case Sema::TDK_SubstitutionFailure:
796-
case Sema::TDK_FailedOverloadResolution:
797788
case Sema::TDK_CUDATargetMismatch:
798789
return nullptr;
799790

@@ -811,14 +802,6 @@ const TemplateArgument *DeductionFailureInfo::getSecondArg() {
811802
return nullptr;
812803
}
813804

814-
Expr *DeductionFailureInfo::getExpr() {
815-
if (static_cast<Sema::TemplateDeductionResult>(Result) ==
816-
Sema::TDK_FailedOverloadResolution)
817-
return static_cast<Expr*>(Data);
818-
819-
return nullptr;
820-
}
821-
822805
llvm::Optional<unsigned> DeductionFailureInfo::getCallArgIndex() {
823806
if (static_cast<Sema::TemplateDeductionResult>(Result) ==
824807
Sema::TDK_DeducedMismatch)
@@ -9699,14 +9682,6 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated,
96999682
return;
97009683
}
97019684

9702-
case Sema::TDK_FailedOverloadResolution: {
9703-
OverloadExpr::FindResult R = OverloadExpr::find(DeductionFailure.getExpr());
9704-
S.Diag(Templated->getLocation(),
9705-
diag::note_ovl_candidate_failed_overload_resolution)
9706-
<< R.Expression->getName();
9707-
return;
9708-
}
9709-
97109685
case Sema::TDK_DeducedMismatch: {
97119686
// Format the template argument list into the argument string.
97129687
SmallString<128> TemplateArgString;
@@ -10043,7 +10018,6 @@ static unsigned RankDeductionFailure(const DeductionFailureInfo &DFI) {
1004310018
return 3;
1004410019

1004510020
case Sema::TDK_InstantiationDepth:
10046-
case Sema::TDK_FailedOverloadResolution:
1004710021
return 4;
1004810022

1004910023
case Sema::TDK_InvalidExplicitArguments:

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,10 +3279,9 @@ DeduceTemplateArgumentByListElement(Sema &S,
32793279
// For all other cases, just match by type.
32803280
QualType ArgType = Arg->getType();
32813281
if (AdjustFunctionParmAndArgTypesForDeduction(S, TemplateParams, ParamType,
3282-
ArgType, Arg, TDF)) {
3283-
Info.Expression = Arg;
3284-
return Sema::TDK_FailedOverloadResolution;
3285-
}
3282+
ArgType, Arg, TDF))
3283+
return Sema::TDK_Success;
3284+
32863285
return DeduceTemplateArgumentsByTypeMatch(S, TemplateParams, ParamType,
32873286
ArgType, Info, Deduced, TDF);
32883287
}

clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,14 @@ namespace initlist_of_array {
220220
namespace init_list_deduction_failure {
221221
void f();
222222
void f(int);
223+
// FIXME: It'd be nice to track that 'T' became a non-deduced context due to
224+
// overload resolution failure for 'f'.
223225
template<typename T> void g(std::initializer_list<T>);
224-
// expected-note@-1 {{candidate template ignored: couldn't resolve reference to overloaded function 'f'}}
225-
void h() { g({f}); }
226-
// expected-error@-1 {{no matching function for call to 'g'}}
226+
// expected-note@-1 {{candidate template ignored: couldn't infer template argument 'T'}}
227+
void h() {
228+
g({f}); // expected-error {{no matching function for call to 'g'}}
229+
g({f, h}); // ok
230+
}
227231
}
228232

229233
namespace deleted_copy {

0 commit comments

Comments
 (0)