-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][Sema] Ignore the parentheses in the guard of DiagnoseUnexpandedParameterPack #86401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…edParameterPack This is a follow-up for llvm#69224, where the previous fix failed to handle the parentheses around the expression. Fixes llvm#86361.
@llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) ChangesThis is a follow-up for #69224, where the previous fix failed to handle the parentheses around the expression. Fixes #86361. Full diff: https://github.com/llvm/llvm-project/pull/86401.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8054d90fc70f93..1bf7d7fcda2a4a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -439,6 +439,8 @@ Bug Fixes to C++ Support
- Fix a crash when instantiating a lambda that captures ``this`` outside of its context. Fixes (#GH85343).
- Fix an issue where a namespace alias could be defined using a qualified name (all name components
following the first `::` were ignored).
+- 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() {
|
✅ With the latest revision this PR passed the Python code formatter. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, seems consistent with the previous patch - thanks!
Hmm, actually - does this fix address /other/ ways a pack could appear, like this? https://godbolt.org/z/oez8TbGqM Presumably a pack could appear in a variety of expressions, not just wrapped in parens - could be in a function call (as in the above example), or nested arbitrarily more deeply in the expression in any number of other expressions? |
It fixes it as well, although with an unused-expression warning. warning: expression result unused [-Wunused-value]
7 | [&](auto... indexes) {
| ^~~~~~~~~~~~~~~~~~~~~~
8 | f1([&] {
| ~~~~~~~~
9 | (ts);
| ~~~~~
10 | indexes;
| ~~~~~~~~
11 | } ...);
| ~~~~~~~
12 | };
| ~ Aside: it crashes again if you turn the capture of the inner lambda to a pack, e.g. |
@dwblaikie Feel free to checkout this patch locally and see if it resolves the original issue - I won't merge it until you confirm it works or discover another issue that goes beyond the scope of this patch. (e.g. another aforementioned issue) |
First glance it seems it does not resolve the original issue (still seeing a crash, with this patch applied, on the original source). I'll try to reduce another test case.
Oh, that surprises me - not sure how ignoring parens could help the case where it's a function call... Oh, I was looking at the wrong parens, it's the line 9
But perhaps this ^ is what you're referring to / when you mention "if you turn the capture of the inner lambda to a pack, e.g.
But is it a different story? Whet I run the above example, with this patch applied, I get an identical stack trace:
|
Yep, the original code still crashes with this PR applied, and the reduced test case comes down to something identical to the code shown in #86401 (comment) with a stack trace that looks the same as the one caused by the test case this patch is addressing. I tend to think this patch is insufficiently general - that there's any number of ways an unexpanded pack could appear inside an expression and ignoring parens is only one fairly narrow case of a broader issue? |
@dwblaikie : You're right. The patch is insufficient because the
... a CallExpr. Admittedly, I don't like the way that this and previous fixes have taken: the assertion we have run into really seems unnecessary because the following Either way, I think I'm going to take a deeper look, probably I should think of a more optimal approach instead of adding such "whack a mole" fixes. I will turn it to draft, probably these issues will get fixed together with my #86265 - I'll notify you when everything is ready. |
Thanks for continuing to look into this! @cor3ntin - perhaps you've got some more thoughts on this too? |
This is a follow-up for #69224, where the previous fix failed to handle the parentheses around the expression.
Fixes #86361.