[clang] 34bd51f - PR44890: Inherit explicitly-specified template arguments into base class

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 15 02:52:44 PST 2020


Author: Richard Smith
Date: 2020-02-15T02:16:21-08:00
New Revision: 34bd51f4b1d9f489e61becb662bdc72bb56dd277

URL: https://github.com/llvm/llvm-project/commit/34bd51f4b1d9f489e61becb662bdc72bb56dd277
DIFF: https://github.com/llvm/llvm-project/commit/34bd51f4b1d9f489e61becb662bdc72bb56dd277.diff

LOG: PR44890: Inherit explicitly-specified template arguments into base class
deduction.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Sema/TemplateDeduction.h b/clang/include/clang/Sema/TemplateDeduction.h
index f787c2689d85..c0af9f3260b6 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -67,6 +67,13 @@ class TemplateDeductionInfo {
   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 {

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index a0b92cdf3a5e..8e3c61819571 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -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);

diff  --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp
index 7268912dd6c5..5218543ab8a4 100644
--- a/clang/test/SemaTemplate/deduction.cpp
+++ b/clang/test/SemaTemplate/deduction.cpp
@@ -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>();
+  }
+}


        


More information about the cfe-commits mailing list