Skip to content

Commit 41ea022

Browse files
authored
[Clang] Fix crash when recovering from an invalid pack indexing type. (#80652)
If the pattern of a pack indexing type did not contain a pack, we would still construct a pack indexing type (to improve error messages) but we would fail to make the type as dependent, leading to infinite recursion when trying to extract a canonical type.
1 parent 2614672 commit 41ea022

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/AST/Type.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,6 +3854,12 @@ PackIndexingType::computeDependence(QualType Pattern, Expr *IndexExpr,
38543854

38553855
if (!(IndexD & TypeDependence::UnexpandedPack))
38563856
TD &= ~TypeDependence::UnexpandedPack;
3857+
3858+
// If the pattern does not contain an unexpended pack,
3859+
// the type is still dependent, and invalid
3860+
if (!Pattern->containsUnexpandedParameterPack())
3861+
TD |= TypeDependence::Error | TypeDependence::DependentInstantiation;
3862+
38573863
return TD;
38583864
}
38593865

clang/test/SemaCXX/cxx2c-pack-indexing.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ void not_pack() {
1111
Tp...[0] c; // expected-error{{'Tp' does not refer to the name of a parameter pack}}
1212
}
1313

14+
template <typename T, auto V, template<typename> typename Tp>
15+
void not_pack_arrays() {
16+
NotAPack...[0] a[1]; // expected-error{{'NotAPack' does not refer to the name of a parameter pack}}
17+
T...[0] b[1]; // expected-error{{'T' does not refer to the name of a parameter pack}}
18+
Tp...[0] c[1]; // expected-error{{'Tp' does not refer to the name of a parameter pack}}
19+
}
20+
21+
template <typename T>
22+
struct TTP;
23+
24+
void test_errors() {
25+
not_pack<int, 0, TTP>();
26+
not_pack_arrays<int, 0, TTP>();
27+
}
28+
1429
namespace invalid_indexes {
1530

1631
int non_constant_index(); // expected-note 2{{declared here}}

0 commit comments

Comments
 (0)