[clang] 09b54e2 - When re-checking an already-substituted template argument, don't lose

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 14:10:09 PST 2020


Author: Richard Smith
Date: 2020-11-03T14:09:54-08:00
New Revision: 09b54e2799a11c6813796c70475d52e09898568b

URL: https://github.com/llvm/llvm-project/commit/09b54e2799a11c6813796c70475d52e09898568b
DIFF: https://github.com/llvm/llvm-project/commit/09b54e2799a11c6813796c70475d52e09898568b.diff

LOG: When re-checking an already-substituted template argument, don't lose
the reference-ness of the parameter's type.

Added: 
    

Modified: 
    clang/lib/Sema/SemaTemplateInstantiate.cpp
    clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index d01189b42ed6..03670e2145c1 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1593,7 +1593,7 @@ TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
   ExprResult SubstReplacement = TransformExpr(E->getReplacement());
   if (SubstReplacement.isInvalid())
     return true;
-  QualType SubstType = TransformType(E->getType());
+  QualType SubstType = TransformType(E->getParameterType(getSema().Context));
   if (SubstType.isNull())
     return true;
   // The type may have been previously dependent and not now, which means we

diff  --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
index 460b6def5d6f..522835f33454 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
@@ -65,3 +65,15 @@ namespace PR42513 {
 
   void use() { f<X1>(); }
 }
+
+namespace ReferenceToConstexpr {
+  struct A { const char *str = "hello"; };
+  constexpr A a;
+  template<const A &r, typename T> struct B {
+    static_assert(__builtin_strcmp(r.str, "hello") == 0, "");
+  };
+  template<const A &r> struct C {
+    template<typename T> void f(B<r, T>, T) {}
+  };
+  void f(C<a> ca) { ca.f({}, 0); }
+}


        


More information about the cfe-commits mailing list