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

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 4 14:46:14 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())
----------------
a-tarasyuk wrote:

Since it's only known to occur with fold expressions, should it just be a bool, or would it be better to use an enum?

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


More information about the cfe-commits mailing list