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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/89257.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+1-1) 
- (modified) clang/test/SemaCXX/cxx2c-pack-indexing.cpp (+6) 


``````````diff
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}}
+}

``````````

</details>


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


More information about the cfe-commits mailing list