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

…ctUnexpandedParameterPacksVisitor

Closes https://github.com/llvm/llvm-project/issues/61460.

We have FunctionParmPackExpr that serves as the unexpanded expression but from 
which the visitor collects none, which may lead to assertion failure during the 
template instantiation.

Actually, we don't need to assert this condition since we would do nothing in 
the subsequent DiagnoseUnexpandedParameterPacks call even if unsatisfied.

>From e8f9d89bda1c5d84ddaa09cf1e328769d39cd50a Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7...@gmail.com>
Date: Mon, 16 Oct 2023 22:50:08 +0800
Subject: [PATCH] [clang][Sema] Don't assert non-empty unexpanded packs
 following CollectUnexpandedParameterPacksVisitor

Closes https://github.com/llvm/llvm-project/issues/61460.

We have FunctionParmPackExpr that serves as the unexpanded
expression but from which the visitor collects none, which may
lead to assertion failure during the template instantiation.

Actually, we don't need to assert this condition since we would
do nothing in the subsequent DiagnoseUnexpandedParameterPacks call
even if unsatisfied.
---
 clang/docs/ReleaseNotes.rst             |  2 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp | 18 ++++++------------
 clang/test/SemaCXX/pr61460.cpp          | 15 +++++++++++++++
 3 files changed, 23 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/pr61460.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9782c123f4c9372..0c70ddf0e9a8b1e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -397,6 +397,8 @@ Bug Fixes in This Version
   operator in C. No longer issuing a confusing diagnostic along the lines of
   "incompatible operand types ('foo' and 'foo')" with extensions such as matrix
   types. Fixes (`#69008 <https://github.com/llvm/llvm-project/issues/69008>`_)
+- Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
+  inside a lambda. (`#61460 
<https://github.com/llvm/llvm-project/issues/61460>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index dfcc78dafdc4c31..b8912b2ad8a372d 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -388,9 +388,8 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
     return false;
 
   SmallVector<UnexpandedParameterPack, 2> Unexpanded;
-  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
-                                                              T->getTypeLoc());
-  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
+  CollectUnexpandedParameterPacksVisitor(Unexpanded)
+      .TraverseTypeLoc(T->getTypeLoc());
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
 
@@ -404,7 +403,6 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
 
   SmallVector<UnexpandedParameterPack, 2> Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
-  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded);
 }
 
@@ -442,8 +440,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
CXXScopeSpec &SS,
 
   SmallVector<UnexpandedParameterPack, 2> Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-    .TraverseNestedNameSpecifier(SS.getScopeRep());
-  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
+      .TraverseNestedNameSpecifier(SS.getScopeRep());
   return DiagnoseUnexpandedParameterPacks(SS.getRange().getBegin(),
                                           UPPC, Unexpanded);
 }
@@ -479,8 +476,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
DeclarationNameInfo &NameInfo,
 
   SmallVector<UnexpandedParameterPack, 2> Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-    .TraverseType(NameInfo.getName().getCXXNameType());
-  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
+      .TraverseType(NameInfo.getName().getCXXNameType());
   return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
 }
 
@@ -493,8 +489,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 
   SmallVector<UnexpandedParameterPack, 2> Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-    .TraverseTemplateName(Template);
-  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
+      .TraverseTemplateName(Template);
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
 
@@ -506,8 +501,7 @@ bool 
Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
 
   SmallVector<UnexpandedParameterPack, 2> Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-    .TraverseTemplateArgumentLoc(Arg);
-  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
+      .TraverseTemplateArgumentLoc(Arg);
   return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
 }
 
diff --git a/clang/test/SemaCXX/pr61460.cpp b/clang/test/SemaCXX/pr61460.cpp
new file mode 100644
index 000000000000000..9433a9a538e160b
--- /dev/null
+++ b/clang/test/SemaCXX/pr61460.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 %s -fsyntax-only -verify
+// expected-no-diagnostics
+template <typename... Ts> void g(Ts... p1s) {
+  (void)[&](auto... p2s) { ([&] { p1s; p2s; }, ...); };
+}                                                       
+void f1() {
+  g();
+}
+
+template <typename... a> void b() {
+  c([] {
+    using d = typename a::e;
+    d::category;
+  }...);
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to