Skip to content

Commit aa22d44

Browse files
authored
[Clang] Do not try to diagnose parameter packs in invalid pack expressions (#89257)
In a pack expression, if the id-expression is not valid, do no try to detect whether it is a pack as that would lead to a crash trying to print a recovery expression. Fixes #88929
1 parent e32c4df commit aa22d44

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

clang/lib/Sema/SemaTemplateVariadic.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,11 @@ ExprResult Sema::ActOnPackIndexingExpr(Scope *S, Expr *PackExpression,
10851085
SourceLocation RSquareLoc) {
10861086
bool isParameterPack = ::isParameterPack(PackExpression);
10871087
if (!isParameterPack) {
1088-
CorrectDelayedTyposInExpr(IndexExpr);
1089-
Diag(PackExpression->getBeginLoc(), diag::err_expected_name_of_pack)
1090-
<< PackExpression;
1088+
if (!PackExpression->containsErrors()) {
1089+
CorrectDelayedTyposInExpr(IndexExpr);
1090+
Diag(PackExpression->getBeginLoc(), diag::err_expected_name_of_pack)
1091+
<< PackExpression;
1092+
}
10911093
return ExprError();
10921094
}
10931095
ExprResult Res =

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,9 @@ void f() {
154154
}
155155

156156
}
157+
158+
namespace GH88929 {
159+
bool b = a...[0]; // expected-error {{use of undeclared identifier 'a'}}
160+
using E = P...[0]; // expected-error {{unknown type name 'P'}} \
161+
// expected-error {{expected ';' after alias declaration}}
162+
}

0 commit comments

Comments
 (0)