Skip to content

Commit 34bd51f

Browse files
committed
PR44890: Inherit explicitly-specified template arguments into base class
deduction.
1 parent b74a381 commit 34bd51f

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

clang/include/clang/Sema/TemplateDeduction.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class TemplateDeductionInfo {
6767
TemplateDeductionInfo(const TemplateDeductionInfo &) = delete;
6868
TemplateDeductionInfo &operator=(const TemplateDeductionInfo &) = delete;
6969

70+
enum ForBaseTag { ForBase };
71+
/// Create temporary template deduction info for speculatively deducing
72+
/// against a base class of an argument's type.
73+
TemplateDeductionInfo(ForBaseTag, const TemplateDeductionInfo &Info)
74+
: Deduced(Info.Deduced), Loc(Info.Loc), DeducedDepth(Info.DeducedDepth),
75+
ExplicitArgs(Info.ExplicitArgs) {}
76+
7077
/// Returns the location at which template argument is
7178
/// occurring.
7279
SourceLocation getLocation() const {

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S,
18181818
// If this is a base class, try to perform template argument
18191819
// deduction from it.
18201820
if (NextT != RecordT) {
1821-
TemplateDeductionInfo BaseInfo(Info.getLocation());
1821+
TemplateDeductionInfo BaseInfo(TemplateDeductionInfo::ForBase, Info);
18221822
Sema::TemplateDeductionResult BaseResult =
18231823
DeduceTemplateArguments(S, TemplateParams, SpecParam,
18241824
QualType(NextT, 0), BaseInfo, Deduced);

clang/test/SemaTemplate/deduction.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,20 @@ namespace nested_packs {
564564
}
565565
#endif
566566
}
567+
568+
namespace PR44890 {
569+
template<typename ...Ts>
570+
struct tuple {};
571+
572+
template<int I, typename ...Ts>
573+
int get0(const tuple<Ts...> &t) { return 0; }
574+
575+
template<typename ...Ts> struct tuple_wrapper : tuple<Ts...> {
576+
template<int I> int get() { return get0<0, Ts...>(*this); }
577+
};
578+
579+
int f() {
580+
tuple_wrapper<int> w;
581+
return w.get<0>();
582+
}
583+
}

0 commit comments

Comments
 (0)