[clang] [clang][Sema] Don't assert non-empty unexpanded packs following Colle… (PR #69224)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 16 09:05:57 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (zyn0217)
<details>
<summary>Changes</summary>
…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.
---
Full diff: https://github.com/llvm/llvm-project/pull/69224.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+2)
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+6-12)
- (added) clang/test/SemaCXX/pr61460.cpp (+8)
``````````diff
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..ee9d1db4bb09486
--- /dev/null
+++ b/clang/test/SemaCXX/pr61460.cpp
@@ -0,0 +1,8 @@
+// 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();
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/69224
More information about the cfe-commits
mailing list