[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-11-12 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 closed 
https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-11-10 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM, thanks

https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-27 Thread Aaron Ballman via cfe-commits


@@ -402,6 +402,19 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
+  // Exception: The `CollectUnexpandedParameterPacksVisitor` collects nothing
+  // from a FunctionParmPackExpr. In the context where the collector is being
+  // used such as `collectUnexpandedParameterPacks`, this type of expression
+  // is not expected to be collected.
+  //
+  // Nonetheless, this function for diagnosis is still called anyway during
+  // template instantiation, with an expression of such a type if we're inside 
a
+  // lambda with unexpanded parameters.
+  //
+  // Rule out this case to prevent the assertion failure.

AaronBallman wrote:

```suggestion
  // CollectUnexpandedParameterPacksVisitor does not expect to see a 
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.
```
Slight rewording.

https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-25 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Done. Sorry for leaving irrelevant changes ;)

https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-25 Thread Younan Zhang via cfe-commits

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

>From 880f271cbad4aacb7647bc402f636adf12ca1147 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 16 Oct 2023 22:50:08 +0800
Subject: [PATCH] [clang][Sema] Avoid non-empty unexpanded pack assertion for
 FunctionParmPackExpr

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.
---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp | 13 +
 clang/test/SemaCXX/pr61460.cpp  | 13 +
 3 files changed, 28 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr61460.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4cc148905d4e130..66f2bc3efefa8bf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -496,6 +496,8 @@ Bug Fixes in This Version
   Fixes (`#65143 `_)
 - Fix crash in formatting the real/imaginary part of a complex lvalue.
   Fixes (`#69218 `_)
+- Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
+  inside a lambda. (`#61460 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index dfcc78dafdc4c31..6ec7fb9ef331190 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -402,6 +402,19 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
+  // Exception: The `CollectUnexpandedParameterPacksVisitor` collects nothing
+  // from a FunctionParmPackExpr. In the context where the collector is being
+  // used such as `collectUnexpandedParameterPacks`, this type of expression
+  // is not expected to be collected.
+  //
+  // Nonetheless, this function for diagnosis is still called anyway during
+  // template instantiation, with an expression of such a type if we're inside 
a
+  // lambda with unexpanded parameters.
+  //
+  // Rule out this case to prevent the assertion failure.
+  if (isa(E) && getEnclosingLambda())
+return false;
+
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
diff --git a/clang/test/SemaCXX/pr61460.cpp b/clang/test/SemaCXX/pr61460.cpp
new file mode 100644
index 000..471b1b39d23c2b7
--- /dev/null
+++ b/clang/test/SemaCXX/pr61460.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++17 %s -fsyntax-only -verify
+
+template  void g(Ts... p1s) {
+  (void)[&](auto... p2s) { ([&] { p1s; p2s; }, ...); };
+}
+
+void f1() {
+  g();
+}
+
+template  void g2(Ts... p1s) {
+  (void)[&](auto... p2s) { [&] { p1s; p2s; }; }; // expected-error 
{{expression contains unexpanded parameter pack 'p2s'}}
+}

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


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-25 Thread via cfe-commits

cor3ntin wrote:

Looks generally good to me. can you remove the whitespace only changes? thanks!

https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-23 Thread Younan Zhang via cfe-commits

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

>From 07749e92c55cb4dfd01e81c9c8413b77c915aa42 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 16 Oct 2023 22:50:08 +0800
Subject: [PATCH 1/2] [clang][Sema] Avoid non-empty unexpanded pack assertion
 for FunctionParmPackExpr

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.
---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp | 26 +++--
 clang/test/SemaCXX/pr61460.cpp  | 13 +
 3 files changed, 35 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/pr61460.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 65c1c07e3ded9f6..7fca89d535aab58 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -470,6 +470,8 @@ Bug Fixes in This Version
   Fixes (`#65143 `_)
 - Fix crash in formatting the real/imaginary part of a complex lvalue.
   Fixes (`#69218 `_)
+- Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
+  inside a lambda. (`#61460 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index dfcc78dafdc4c31..521d34dc18d0166 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -388,8 +388,8 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 return false;
 
   SmallVector Unexpanded;
-  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
-  T->getTypeLoc());
+  CollectUnexpandedParameterPacksVisitor(Unexpanded)
+  .TraverseTypeLoc(T->getTypeLoc());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
@@ -402,6 +402,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
+  // Exception: The `CollectUnexpandedParameterPacksVisitor` collects nothing
+  // from a FunctionParmPackExpr. In the context where the collector is being
+  // used such as `collectUnexpandedParameterPacks`, this type of expression
+  // is not expected to be collected.
+  //
+  // Nonetheless, this function for diagnosis is still called anyway during
+  // template instantiation, with an expression of such a type if we're inside 
a
+  // lambda with unexpanded parameters.
+  //
+  // Rule out this case to prevent the assertion failure.
+  if (auto *Expr = dyn_cast(E);
+  Expr && getEnclosingLambda())
+return false;
+
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
@@ -442,7 +456,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
CXXScopeSpec ,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseNestedNameSpecifier(SS.getScopeRep());
+  .TraverseNestedNameSpecifier(SS.getScopeRep());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(SS.getRange().getBegin(),
   UPPC, Unexpanded);
@@ -479,7 +493,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
DeclarationNameInfo ,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseType(NameInfo.getName().getCXXNameType());
+  .TraverseType(NameInfo.getName().getCXXNameType());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
 }
@@ -493,7 +507,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseTemplateName(Template);
+  .TraverseTemplateName(Template);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
@@ -506,7 +520,7 @@ bool 
Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseTemplateArgumentLoc(Arg);
+  .TraverseTemplateArgumentLoc(Arg);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, 

[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-23 Thread Younan Zhang via cfe-commits

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

>From ec6425590890e050dc212a7e13ca27c866a4fb22 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 16 Oct 2023 22:50:08 +0800
Subject: [PATCH 1/2] [clang][Sema] Avoid non-empty unexpanded pack assertion
 for FunctionParmPackExpr

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.
---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp | 26 +++--
 clang/test/SemaCXX/pr61460.cpp  | 13 +
 3 files changed, 35 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/pr61460.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c292e012c4548d9..ea7a29b098a80ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -476,6 +476,8 @@ Bug Fixes in This Version
   Fixes (`#65143 `_)
 - Fix crash in formatting the real/imaginary part of a complex lvalue.
   Fixes (`#69218 `_)
+- Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
+  inside a lambda. (`#61460 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index dfcc78dafdc4c31..521d34dc18d0166 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -388,8 +388,8 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 return false;
 
   SmallVector Unexpanded;
-  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
-  T->getTypeLoc());
+  CollectUnexpandedParameterPacksVisitor(Unexpanded)
+  .TraverseTypeLoc(T->getTypeLoc());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
@@ -402,6 +402,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
+  // Exception: The `CollectUnexpandedParameterPacksVisitor` collects nothing
+  // from a FunctionParmPackExpr. In the context where the collector is being
+  // used such as `collectUnexpandedParameterPacks`, this type of expression
+  // is not expected to be collected.
+  //
+  // Nonetheless, this function for diagnosis is still called anyway during
+  // template instantiation, with an expression of such a type if we're inside 
a
+  // lambda with unexpanded parameters.
+  //
+  // Rule out this case to prevent the assertion failure.
+  if (auto *Expr = dyn_cast(E);
+  Expr && getEnclosingLambda())
+return false;
+
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
@@ -442,7 +456,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
CXXScopeSpec ,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseNestedNameSpecifier(SS.getScopeRep());
+  .TraverseNestedNameSpecifier(SS.getScopeRep());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(SS.getRange().getBegin(),
   UPPC, Unexpanded);
@@ -479,7 +493,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
DeclarationNameInfo ,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseType(NameInfo.getName().getCXXNameType());
+  .TraverseType(NameInfo.getName().getCXXNameType());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
 }
@@ -493,7 +507,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseTemplateName(Template);
+  .TraverseTemplateName(Template);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
@@ -506,7 +520,7 @@ bool 
Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseTemplateArgumentLoc(Arg);
+  .TraverseTemplateArgumentLoc(Arg);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, 

[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-23 Thread Younan Zhang via cfe-commits


@@ -402,6 +402,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
+  // Exception: The `CollectUnexpandedParameterPacksVisitor` collects nothing
+  // from a FunctionParmPackExpr. In the context where the collector is being
+  // used such as `collectUnexpandedParameterPacks`, this type of expression
+  // is not expected to be collected.
+  //
+  // Nonetheless, this function for diagnosis is still called anyway during
+  // template instantiation, with an expression of such a type if we're inside 
a
+  // lambda with unexpanded parameters.
+  //
+  // Rule out this case to prevent the assertion failure.
+  if (auto *Expr = dyn_cast(E);
+  Expr && getEnclosingLambda())

zyn0217 wrote:

Thanks, I almost forget it ;)

https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-23 Thread Timm Baeder via cfe-commits


@@ -402,6 +402,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
+  // Exception: The `CollectUnexpandedParameterPacksVisitor` collects nothing
+  // from a FunctionParmPackExpr. In the context where the collector is being
+  // used such as `collectUnexpandedParameterPacks`, this type of expression
+  // is not expected to be collected.
+  //
+  // Nonetheless, this function for diagnosis is still called anyway during
+  // template instantiation, with an expression of such a type if we're inside 
a
+  // lambda with unexpanded parameters.
+  //
+  // Rule out this case to prevent the assertion failure.
+  if (auto *Expr = dyn_cast(E);
+  Expr && getEnclosingLambda())

tbaederr wrote:

```suggestion
  if (isa(E) && getEnclosingLambda())
```

https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-22 Thread via cfe-commits

cor3ntin wrote:

> Instead of putting it inside an assertion, how about adding a check for 
> FunctionParmPackExpr separately? I mean,

If that works it would be fine with me, yes

https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-21 Thread Younan Zhang via cfe-commits

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

>From 89e486690f1a28900152d4eef023be6fdfcf296a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 16 Oct 2023 22:50:08 +0800
Subject: [PATCH] [clang][Sema] Avoid non-empty unexpanded pack assertion for
 FunctionParmPackExpr

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.
---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp | 26 +++--
 clang/test/SemaCXX/pr61460.cpp  | 13 +
 3 files changed, 35 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/pr61460.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a9a67f7451c092..e05bd9251702964 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -438,6 +438,8 @@ Bug Fixes in This Version
 - Clang no longer permits using the `_BitInt` types as an underlying type for 
an
   enumeration as specified in the C23 Standard.
   Fixes (`#69619 `_)
+- Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
+  inside a lambda. (`#61460 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index dfcc78dafdc4c31..521d34dc18d0166 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -388,8 +388,8 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 return false;
 
   SmallVector Unexpanded;
-  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
-  T->getTypeLoc());
+  CollectUnexpandedParameterPacksVisitor(Unexpanded)
+  .TraverseTypeLoc(T->getTypeLoc());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
@@ -402,6 +402,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
+  // Exception: The `CollectUnexpandedParameterPacksVisitor` collects nothing
+  // from a FunctionParmPackExpr. In the context where the collector is being
+  // used such as `collectUnexpandedParameterPacks`, this type of expression
+  // is not expected to be collected.
+  //
+  // Nonetheless, this function for diagnosis is still called anyway during
+  // template instantiation, with an expression of such a type if we're inside 
a
+  // lambda with unexpanded parameters.
+  //
+  // Rule out this case to prevent the assertion failure.
+  if (auto *Expr = dyn_cast(E);
+  Expr && getEnclosingLambda())
+return false;
+
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
@@ -442,7 +456,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
CXXScopeSpec ,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseNestedNameSpecifier(SS.getScopeRep());
+  .TraverseNestedNameSpecifier(SS.getScopeRep());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(SS.getRange().getBegin(),
   UPPC, Unexpanded);
@@ -479,7 +493,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const 
DeclarationNameInfo ,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseType(NameInfo.getName().getCXXNameType());
+  .TraverseType(NameInfo.getName().getCXXNameType());
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
 }
@@ -493,7 +507,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation 
Loc,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseTemplateName(Template);
+  .TraverseTemplateName(Template);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
 }
@@ -506,7 +520,7 @@ bool 
Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
 
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor(Unexpanded)
-.TraverseTemplateArgumentLoc(Arg);
+  .TraverseTemplateArgumentLoc(Arg);
   assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
   return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
 }
diff 

[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-21 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 edited 
https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (PR #69224)

2023-10-21 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 edited 
https://github.com/llvm/llvm-project/pull/69224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits