PR44890: Inherit explicitly-specified template arguments into base class
authorRichard Smith <richard@metafoo.co.uk>
Sat, 15 Feb 2020 10:15:26 +0000 (02:15 -0800)
committerRichard Smith <richard@metafoo.co.uk>
Sat, 15 Feb 2020 10:16:21 +0000 (02:16 -0800)
deduction.

clang/include/clang/Sema/TemplateDeduction.h
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaTemplate/deduction.cpp

index f787c26..c0af9f3 100644 (file)
@@ -67,6 +67,13 @@ public:
   TemplateDeductionInfo(const TemplateDeductionInfo &) = delete;
   TemplateDeductionInfo &operator=(const TemplateDeductionInfo &) = delete;
 
+  enum ForBaseTag { ForBase };
+  /// Create temporary template deduction info for speculatively deducing
+  /// against a base class of an argument's type.
+  TemplateDeductionInfo(ForBaseTag, const TemplateDeductionInfo &Info)
+      : Deduced(Info.Deduced), Loc(Info.Loc), DeducedDepth(Info.DeducedDepth),
+        ExplicitArgs(Info.ExplicitArgs) {}
+
   /// Returns the location at which template argument is
   /// occurring.
   SourceLocation getLocation() const {
index a0b92cd..8e3c618 100644 (file)
@@ -1818,7 +1818,7 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S,
         // If this is a base class, try to perform template argument
         // deduction from it.
         if (NextT != RecordT) {
-          TemplateDeductionInfo BaseInfo(Info.getLocation());
+          TemplateDeductionInfo BaseInfo(TemplateDeductionInfo::ForBase, Info);
           Sema::TemplateDeductionResult BaseResult =
               DeduceTemplateArguments(S, TemplateParams, SpecParam,
                                       QualType(NextT, 0), BaseInfo, Deduced);
index 7268912..5218543 100644 (file)
@@ -564,3 +564,20 @@ namespace nested_packs {
   }
 #endif
 }
+
+namespace PR44890 {
+  template<typename ...Ts>
+    struct tuple {};
+
+  template<int I, typename ...Ts>
+    int get0(const tuple<Ts...> &t) { return 0; }
+
+  template<typename ...Ts> struct tuple_wrapper : tuple<Ts...> {
+    template<int I> int get() { return get0<0, Ts...>(*this); }
+  };
+
+  int f() {
+    tuple_wrapper<int> w;
+    return w.get<0>();
+  }
+}