Skip to content

Commit d22b9ba

Browse files
cor3ntinagozillon
authored andcommitted
[Clang] Fix a crash when dumping a pack indexing type. (llvm#80439)
Fix a crash caused by incorrect assumptions Reported here llvm#72644 (comment)
1 parent 7d2a4d8 commit d22b9ba

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

clang/lib/AST/TypePrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,10 +1195,10 @@ void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) {
11951195

11961196
void TypePrinter::printPackIndexingBefore(const PackIndexingType *T,
11971197
raw_ostream &OS) {
1198-
if (T->isInstantiationDependentType())
1199-
OS << T->getPattern() << "...[" << T->getIndexExpr() << "]";
1200-
else
1198+
if (T->hasSelectedType())
12011199
OS << T->getSelectedType();
1200+
else
1201+
OS << T->getPattern() << "...[" << T->getIndexExpr() << "]";
12021202
spaceBeforePlaceHolder(OS);
12031203
}
12041204

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: not %clang_cc1 -std=c++2c -ast-dump %s | FileCheck %s
2+
3+
namespace InvalidPacksShouldNotCrash {
4+
5+
struct NotAPack;
6+
template <typename T, auto V, template<typename> typename Tp>
7+
void not_pack() {
8+
int i = 0;
9+
i...[0]; // expected-error {{i does not refer to the name of a parameter pack}}
10+
V...[0]; // expected-error {{V does not refer to the name of a parameter pack}}
11+
NotAPack...[0] a; // expected-error{{'NotAPack' does not refer to the name of a parameter pack}}
12+
T...[0] b; // expected-error{{'T' does not refer to the name of a parameter pack}}
13+
Tp...[0] c; // expected-error{{'Tp' does not refer to the name of a parameter pack}}
14+
}
15+
16+
// CHECK: FunctionDecl {{.*}} not_pack 'void ()'
17+
// CHECK: DeclStmt {{.*}}
18+
// CHECK: DeclStmt {{.*}}
19+
// CHECK-NEXT: VarDecl {{.*}} a 'NotAPack...{{.*}}'
20+
// CHECK-NEXT: DeclStmt {{.*}}
21+
// CHECK-NEXT: VarDecl {{.*}} 'T...{{.*}}'
22+
// CHECK-NEXT: DeclStmt {{.*}}
23+
// CHECK-NEXT: VarDecl {{.*}} c 'Tp...{{.*}}'
24+
25+
}

0 commit comments

Comments
 (0)