Skip to content

Commit 5a684b7

Browse files
committed
Ensure we don't strip the ConstantExpr carrying a non-type template
argument's value off it during substitution.
1 parent 7bd3702 commit 5a684b7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,9 @@ TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
15971597
ExprResult
15981598
TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
15991599
SubstNonTypeTemplateParmExpr *E) {
1600-
ExprResult SubstReplacement = TransformExpr(E->getReplacement());
1600+
ExprResult SubstReplacement = E->getReplacement();
1601+
if (!isa<ConstantExpr>(SubstReplacement.get()))
1602+
SubstReplacement = TransformExpr(E->getReplacement());
16011603
if (SubstReplacement.isInvalid())
16021604
return true;
16031605
QualType SubstType = TransformType(E->getParameterType(getSema().Context));

clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,18 @@ namespace dependent_reference {
511511
// Ensure that we can instantiate the definition of S<...>.
512512
int n = *v.q + *w.q;
513513
}
514+
515+
namespace decay {
516+
template<typename T, typename C, const char *const A[(int)T::count]> struct X {
517+
template<typename CC> void f(const X<T, CC, A> &v) {}
518+
};
519+
struct A {
520+
static constexpr const char *arr[] = {"hello", "world"};
521+
static constexpr int count = 2;
522+
};
523+
void f() {
524+
X<A, int, A::arr> x1;
525+
X<A, float, A::arr> x2;
526+
x1.f(x2);
527+
}
528+
}

0 commit comments

Comments
 (0)