[clang] [Clang] omit parentheses in fold expressions with a single expansion (PR #110761)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 2 07:26:31 PDT 2024
================
@@ -15598,6 +15598,9 @@ TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
E->getOperator());
+ if (*NumExpansions == 1)
----------------
erichkeane wrote:
This needs a comment/examples to show why this is happening.
I'm not completely familiar with this instantiation, but I have a few things to think about:
1- Make sure that we ONLY omit the parens in cases where this is a full instantiation, if we do it on partial instantiations, I think we get that wrong.
2- Make sure we do this in both left and right folds, there is some work above that seems to do this differently in right-fold inits.
3- Should we be doing the ignore-parens on the pattern/before instantiation, rather than after? I'm trying to figure out if there is good reason why/why not.
4- Are there examples where this ISN'T correct we could defend against? Something like:
`if ( (a == 0) or ... && (b == 0) or ...)` (or something similar, where we are expanding two packs, and the parens might be meaningful).
Those situations aren't really concerning for us during normal compilation, but it could mean an AST print would get parsed differently than we mean it.
https://github.com/llvm/llvm-project/pull/110761
More information about the cfe-commits
mailing list