diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index d01189b42ed60..03670e2145c1f 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 460b6def5d6f3..522835f33454c 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); } +}