From 09b54e2799a11c6813796c70475d52e09898568b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 3 Nov 2020 14:02:56 -0800 Subject: [PATCH] When re-checking an already-substituted template argument, don't lose the reference-ness of the parameter's type. --- clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 +- clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index d01189b..03670e2 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 460b6de..522835f 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(); } } + +namespace ReferenceToConstexpr { + struct A { const char *str = "hello"; }; + constexpr A a; + template struct B { + static_assert(__builtin_strcmp(r.str, "hello") == 0, ""); + }; + template struct C { + template void f(B, T) {} + }; + void f(C ca) { ca.f({}, 0); } +} -- 2.7.4