Skip to content

Commit 297953b

Browse files
committed
[clang] WIP: remove workaround for SubstNonTypeTemplateParmExpr transform
1 parent a5bff94 commit 297953b

File tree

2 files changed

+7
-33
lines changed

2 files changed

+7
-33
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,40 +2446,14 @@ TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
24462446
SubstReplacement = TransformExpr(E->getReplacement());
24472447
if (SubstReplacement.isInvalid())
24482448
return true;
2449-
QualType SubstType = TransformType(E->getParameterType(getSema().Context));
2450-
if (SubstType.isNull())
2451-
return true;
2452-
// The type may have been previously dependent and not now, which means we
2453-
// might have to implicit cast the argument to the new type, for example:
2454-
// template<auto T, decltype(T) U>
2455-
// concept C = sizeof(U) == 4;
2456-
// void foo() requires C<2, 'a'> { }
2457-
// When normalizing foo(), we first form the normalized constraints of C:
2458-
// AtomicExpr(sizeof(U) == 4,
2459-
// U=SubstNonTypeTemplateParmExpr(Param=U,
2460-
// Expr=DeclRef(U),
2461-
// Type=decltype(T)))
2462-
// Then we substitute T = 2, U = 'a' into the parameter mapping, and need to
2463-
// produce:
2464-
// AtomicExpr(sizeof(U) == 4,
2465-
// U=SubstNonTypeTemplateParmExpr(Param=U,
2466-
// Expr=ImpCast(
2467-
// decltype(2),
2468-
// SubstNTTPE(Param=U, Expr='a',
2469-
// Type=char)),
2470-
// Type=decltype(2)))
2471-
// The call to CheckTemplateArgument here produces the ImpCast.
2472-
TemplateArgument SugaredConverted, CanonicalConverted;
2473-
if (SemaRef
2474-
.CheckTemplateArgument(E->getParameter(), SubstType,
2475-
SubstReplacement.get(), SugaredConverted,
2476-
CanonicalConverted,
2477-
/*StrictCheck=*/false, Sema::CTAK_Specified)
2478-
.isInvalid())
2449+
auto *Param = cast_or_null<NonTypeTemplateParmDecl>(
2450+
TransformDecl(E->getNameLoc(), E->getParameter()));
2451+
if (!Param)
24792452
return true;
24802453
return transformNonTypeTemplateParmRef(
2481-
E->getAssociatedDecl(), E->getParameter(), E->getExprLoc(),
2482-
SugaredConverted, E->getPackIndex(), E->getFinal());
2454+
E->getAssociatedDecl(), Param, E->getExprLoc(),
2455+
TemplateArgument(SubstReplacement.get(), /*IsCanonical=*/false),
2456+
E->getPackIndex(), E->getFinal());
24832457
}
24842458

24852459
ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(ValueDecl *PD,

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ using Bar = Foo<X, sizeof(X)>; // expected-note {{candidate template ignored: co
113113
// expected-note {{implicit deduction guide declared as 'template <typename X> requires __is_deducible(test9::Bar, test9::Foo<X, sizeof(X)>) Bar(test9::Foo<X, sizeof(X)>) -> test9::Foo<X, sizeof(X)>'}} \
114114
// expected-note {{implicit deduction guide declared as 'template <typename X> requires __is_deducible(test9::Bar, test9::Foo<X, sizeof(X)>) Bar(const X (&)[sizeof(X)]) -> test9::Foo<X, sizeof(X)>'}} \
115115
// expected-note {{candidate template ignored: constraints not satisfied [with X = int]}} \
116-
// expected-note {{cannot deduce template arguments for 'test9::Bar' from 'test9::Foo<int, 4UL>'}}
116+
// expected-note {{cannot deduce template arguments for 'test9::Bar' from 'test9::Foo<int, sizeof(int)>'}}
117117

118118

119119
Bar s = {{1}}; // expected-error {{no viable constructor or deduction guide }}

0 commit comments

Comments
 (0)