@@ -103,12 +103,12 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S,
103
103
bool PartialOrdering = false );
104
104
105
105
static Sema::TemplateDeductionResult
106
- DeduceTemplateArguments (Sema &S,
107
- TemplateParameterList *TemplateParams,
106
+ DeduceTemplateArguments (Sema &S, TemplateParameterList *TemplateParams,
108
107
const TemplateArgument *Params, unsigned NumParams,
109
108
const TemplateArgument *Args, unsigned NumArgs,
110
109
TemplateDeductionInfo &Info,
111
- SmallVectorImpl<DeducedTemplateArgument> &Deduced);
110
+ SmallVectorImpl<DeducedTemplateArgument> &Deduced,
111
+ bool NumberOfArgumentsMustMatch);
112
112
113
113
// / \brief If the given expression is of a form that permits the deduction
114
114
// / of a non-type template parameter, return the declaration of that
@@ -453,10 +453,10 @@ DeduceTemplateArguments(Sema &S,
453
453
// Perform template argument deduction on each template
454
454
// argument. Ignore any missing/extra arguments, since they could be
455
455
// filled in by default arguments.
456
- return DeduceTemplateArguments (S, TemplateParams,
457
- Param->getArgs (), Param-> getNumArgs (),
458
- SpecArg->getArgs (), SpecArg-> getNumArgs () ,
459
- Info, Deduced );
456
+ return DeduceTemplateArguments (S, TemplateParams, Param-> getArgs (),
457
+ Param->getNumArgs (), SpecArg-> getArgs (),
458
+ SpecArg->getNumArgs (), Info, Deduced ,
459
+ /* NumberOfArgumentsMustMatch= */ false );
460
460
}
461
461
462
462
// If the argument type is a class template specialization, we
@@ -487,11 +487,10 @@ DeduceTemplateArguments(Sema &S,
487
487
return Result;
488
488
489
489
// Perform template argument deduction for the template arguments.
490
- return DeduceTemplateArguments (S, TemplateParams,
491
- Param->getArgs (), Param->getNumArgs (),
492
- SpecArg->getTemplateArgs ().data (),
493
- SpecArg->getTemplateArgs ().size (),
494
- Info, Deduced);
490
+ return DeduceTemplateArguments (
491
+ S, TemplateParams, Param->getArgs (), Param->getNumArgs (),
492
+ SpecArg->getTemplateArgs ().data (), SpecArg->getTemplateArgs ().size (),
493
+ Info, Deduced, /* NumberOfArgumentsMustMatch=*/ true );
495
494
}
496
495
497
496
// / \brief Determines whether the given type is an opaque type that
@@ -1461,6 +1460,7 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S,
1461
1460
SmallVector<const RecordType *, 8 > ToVisit;
1462
1461
ToVisit.push_back (RecordT);
1463
1462
bool Successful = false ;
1463
+ SmallVector<DeducedTemplateArgument, 8 > SuccessfulDeduced;
1464
1464
while (!ToVisit.empty ()) {
1465
1465
// Retrieve the next class in the inheritance hierarchy.
1466
1466
const RecordType *NextT = ToVisit.pop_back_val ();
@@ -1481,14 +1481,20 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S,
1481
1481
// note that we had some success. Otherwise, ignore any deductions
1482
1482
// from this base class.
1483
1483
if (BaseResult == Sema::TDK_Success) {
1484
+ // If we've already seen some success, then deduction fails due to
1485
+ // an ambiguity (temp.deduct.call p5).
1486
+ if (Successful)
1487
+ return Sema::TDK_MiscellaneousDeductionFailure;
1488
+
1484
1489
Successful = true ;
1485
- DeducedOrig. clear ( );
1486
- DeducedOrig. append (Deduced. begin (), Deduced. end ());
1490
+ std::swap (SuccessfulDeduced, Deduced );
1491
+
1487
1492
Info.Param = BaseInfo.Param ;
1488
1493
Info.FirstArg = BaseInfo.FirstArg ;
1489
1494
Info.SecondArg = BaseInfo.SecondArg ;
1490
- } else
1491
- Deduced = DeducedOrig;
1495
+ }
1496
+
1497
+ Deduced = DeducedOrig;
1492
1498
}
1493
1499
1494
1500
// Visit base classes
@@ -1500,8 +1506,10 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S,
1500
1506
}
1501
1507
}
1502
1508
1503
- if (Successful)
1509
+ if (Successful) {
1510
+ std::swap (SuccessfulDeduced, Deduced);
1504
1511
return Sema::TDK_Success;
1512
+ }
1505
1513
1506
1514
return Result;
1507
1515
}
@@ -1825,12 +1833,12 @@ static bool hasPackExpansionBeforeEnd(const TemplateArgument *Args,
1825
1833
}
1826
1834
1827
1835
static Sema::TemplateDeductionResult
1828
- DeduceTemplateArguments (Sema &S,
1829
- TemplateParameterList *TemplateParams,
1836
+ DeduceTemplateArguments (Sema &S, TemplateParameterList *TemplateParams,
1830
1837
const TemplateArgument *Params, unsigned NumParams,
1831
1838
const TemplateArgument *Args, unsigned NumArgs,
1832
1839
TemplateDeductionInfo &Info,
1833
- SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
1840
+ SmallVectorImpl<DeducedTemplateArgument> &Deduced,
1841
+ bool NumberOfArgumentsMustMatch) {
1834
1842
// C++0x [temp.deduct.type]p9:
1835
1843
// If the template argument list of P contains a pack expansion that is not
1836
1844
// the last template argument, the entire template argument list is a
@@ -1850,7 +1858,8 @@ DeduceTemplateArguments(Sema &S,
1850
1858
1851
1859
// Check whether we have enough arguments.
1852
1860
if (!hasTemplateArgumentForDeduction (Args, ArgIdx, NumArgs))
1853
- return Sema::TDK_Success;
1861
+ return NumberOfArgumentsMustMatch ? Sema::TDK_TooFewArguments
1862
+ : Sema::TDK_Success;
1854
1863
1855
1864
if (Args[ArgIdx].isPackExpansion ()) {
1856
1865
// FIXME: We follow the logic of C++0x [temp.deduct.type]p22 here,
@@ -1921,7 +1930,7 @@ DeduceTemplateArguments(Sema &S,
1921
1930
return DeduceTemplateArguments (S, TemplateParams,
1922
1931
ParamList.data (), ParamList.size (),
1923
1932
ArgList.data (), ArgList.size (),
1924
- Info, Deduced);
1933
+ Info, Deduced, false );
1925
1934
}
1926
1935
1927
1936
// / \brief Determine whether two template arguments are the same.
0 commit comments