[clang] [Clang] omit parentheses in fold expressions with a single expansion (PR #110761)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 4 14:24:47 PDT 2024


================
@@ -15609,6 +15609,14 @@ TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
       return true;
   }
 
+  // When there's only one expansion, the parentheses can be safely eliminated
+  // to avoid any extra redundancy that may result in incorrect checks.
+  // For example, transforming (((args == 0) || ...)) into (args == 0)
+  // allows the omission of parentheses while ensuring precise representation
+  // and avoiding warnings regarding redundant parentheses.
+  if (*NumExpansions == 1 && !E->isTypeDependent())
----------------
erichkeane wrote:

I don't think this is right, decltype isn't the only situation where this could be type dependent.  I think we really do have to settle for putting a 'bit' on `ParenExpr`.

https://github.com/llvm/llvm-project/pull/110761


More information about the cfe-commits mailing list