[clang] [clang][Sema] Ignore the parentheses in the guard of DiagnoseUnexpandedParameterPack (PR #86401)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 23 09:09:45 PDT 2024


https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/86401

This is a follow-up for https://github.com/llvm/llvm-project/pull/69224, where the previous fix failed to handle the parentheses around the expression.

Fixes https://github.com/llvm/llvm-project/issues/86361.

>From 1a990278196bf9c8753fe318f060f17fb8d0e669 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Sun, 24 Mar 2024 00:00:31 +0800
Subject: [PATCH] [clang][Sema] Ignore the parentheses in the guard of
 DiagnoseUnexpandedParameterPack

This is a follow-up for https://github.com/llvm/llvm-project/pull/69224,
where the previous fix failed to handle the parentheses around the
expression.

Fixes https://github.com/llvm/llvm-project/issues/86361.
---
 clang/docs/ReleaseNotes.rst             | 2 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp | 2 +-
 clang/test/SemaCXX/pr61460.cpp          | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 690fc7ed271a3d..9c3dec4d17e022 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -344,6 +344,8 @@ Bug Fixes to C++ Support
   when one of the function had more specialized templates.
   Fixes (`#82509 <https://github.com/llvm/llvm-project/issues/82509>`_)
   and (`#74494 <https://github.com/llvm/llvm-project/issues/74494>`_)
+- A follow-up fix was added for (#GH61460), where the fix previously overlooked the parentheses
+  around the expression. (#GH86361)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 903fbfd18e779c..1c4a09bca4e3ff 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -415,7 +415,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   // FunctionParmPackExpr, but diagnosing unexpected parameter packs may still
   // see such an expression in a lambda body.
   // We'll bail out early in this case to avoid triggering an assertion.
-  if (isa<FunctionParmPackExpr>(E) && getEnclosingLambda())
+  if (isa<FunctionParmPackExpr>(E->IgnoreParens()) && getEnclosingLambda())
     return false;
 
   SmallVector<UnexpandedParameterPack, 2> Unexpanded;
diff --git a/clang/test/SemaCXX/pr61460.cpp b/clang/test/SemaCXX/pr61460.cpp
index 471b1b39d23c2b..44a11c30b95b59 100644
--- a/clang/test/SemaCXX/pr61460.cpp
+++ b/clang/test/SemaCXX/pr61460.cpp
@@ -2,6 +2,7 @@
 
 template <typename... Ts> void g(Ts... p1s) {
   (void)[&](auto... p2s) { ([&] { p1s; p2s; }, ...); };
+  (void)[&](auto... p2s) { ([&] { (p1s); p2s; }, ...); };
 }
 
 void f1() {



More information about the cfe-commits mailing list