Skip to content

Commit eae5075

Browse files
committed
[clang] Use canonical type for substitution which might be incomplete
When checking deduction consistency, a substitution can be incomplete such that only sugar parts refer to non-deduced template parameters. This would not otherwise lead to an inconsistent deduction, so this patch makes it so we canonicalize the types before substitution in order to avoid that possibility, for now. When we are able to produce substitution failure diagnostics for partial ordering, we might want to improve the TemplateInstantiator so that it does not fail in that case. This fixes a regression on top of #100692, which was reported on the PR. This was never released, so there are no release notes.
1 parent 39a4b32 commit eae5075

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5505,8 +5505,11 @@ static TemplateDeductionResult CheckDeductionConsistency(
55055505
Sema::ArgumentPackSubstitutionIndexRAII PackIndex(
55065506
S, ArgIdx != -1 ? ::getPackIndexForParam(S, FTD, MLTAL, ArgIdx) : -1);
55075507
bool IsIncompleteSubstitution = false;
5508-
QualType InstP = S.SubstType(P, MLTAL, FTD->getLocation(), FTD->getDeclName(),
5509-
&IsIncompleteSubstitution);
5508+
// FIXME: A substitution can be incomplete on a non-structural part of the
5509+
// type. Use the canonical type for now, until the TemplateInstantiator can
5510+
// deal with that.
5511+
QualType InstP = S.SubstType(P.getCanonicalType(), MLTAL, FTD->getLocation(),
5512+
FTD->getDeclName(), &IsIncompleteSubstitution);
55105513
if (InstP.isNull() && !IsIncompleteSubstitution)
55115514
return TemplateDeductionResult::SubstitutionFailure;
55125515
if (!CheckConsistency)

clang/test/SemaTemplate/GH18291.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,12 @@ namespace static_vs_nonstatic {
112112
}
113113
} // namespace explicit_obj_param
114114
} // namespace static_vs_nonstatic
115+
116+
namespace incomplete_on_sugar {
117+
template <unsigned P, class T> void f(T[P]) = delete;
118+
template <unsigned P> void f(int[][P]);
119+
void test() {
120+
int array[1][8];
121+
f<8>(array);
122+
}
123+
} // namespace incomplete_on_sugar

0 commit comments

Comments
 (0)