[clang] [Clang] Do not try to diagnose parameter packs in invalid pack expres… (PR #89257)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 18 09:07:45 PDT 2024


https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/89257

…sions

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

>From 6a000c3f2da8497a691000bfabc81211a85292a4 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Thu, 18 Apr 2024 18:02:45 +0200
Subject: [PATCH] [Clang] Do not try to diagnose parameter packs in invalid
 pack expressions

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
---
 clang/lib/Sema/SemaTemplateVariadic.cpp    | 2 +-
 clang/test/SemaCXX/cxx2c-pack-indexing.cpp | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 4909414c0c78d4..2fdd5aeb736883 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1084,7 +1084,7 @@ ExprResult Sema::ActOnPackIndexingExpr(Scope *S, Expr *PackExpression,
                                        Expr *IndexExpr,
                                        SourceLocation RSquareLoc) {
   bool isParameterPack = ::isParameterPack(PackExpression);
-  if (!isParameterPack) {
+  if (!PackExpression->containsErrors() && !isParameterPack) {
     CorrectDelayedTyposInExpr(IndexExpr);
     Diag(PackExpression->getBeginLoc(), diag::err_expected_name_of_pack)
         << PackExpression;
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index e13635383b6ca6..606715e6aacffd 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -154,3 +154,9 @@ void f() {
 }
 
 }
+
+namespace GH88929 {
+    bool b = a...[0];  // expected-error {{use of undeclared identifier 'a'}}
+    using E = P...[0]; // expected-error {{unknown type name 'P'}} \
+                       // expected-error {{expected ';' after alias declaration}}
+}



More information about the cfe-commits mailing list