[clang] [clang-format][NFC] Simplify some logic in BreakableLineCommentSection (PR #148324)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 13 20:33:49 PDT 2025


================
@@ -927,14 +927,12 @@ BreakableLineCommentSection::BreakableLineCommentSection(
       }
 
       if (Lines[i].size() != IndentPrefix.size()) {
-        PrefixSpaceChange[i] = FirstLineSpaceChange;
+        assert(Lines[i].size() > IndentPrefix.size());
 
-        if (SpacesInPrefix + PrefixSpaceChange[i] < Minimum) {
-          PrefixSpaceChange[i] +=
-              Minimum - (SpacesInPrefix + PrefixSpaceChange[i]);
-        }
+        PrefixSpaceChange[i] = SpacesInPrefix + FirstLineSpaceChange < Minimum
----------------
owenca wrote:

Like the examples of [conditional/ternary operators](https://en.cppreference.com/w/cpp/language/operator_other.html#Conditional_operator), I never add redundant parentheses because they have the lowest precedence relative to arithmetic/logical operators. This is analogous to `a + (b * c)` or `(a / b) - c`.

The clang-format codebase has a mixture of both `expr1 ? expr2 : expr3` and `(expr1) ? expr2 : expr3`, and IMO we should consistently use the former. Although I can understand why some people prefer the latter when `expr1` and `expr2` are on the same line, there's really nothing to gain when the questions mark starts on a new line:
```
expr1
    ? expr2
```

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


More information about the cfe-commits mailing list