aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/ContinuationIndenter.cpp
AgeCommit message (Collapse)AuthorFilesLines
3 days[clang-format] Stop ctor initializer from being inlined (#150361)Eric Li1-1/+2
The colon in a constructor's initializer list triggers the inlining of a nested block as if it was a conditional operator expression. This prevents line breaks under certain circumstances when the initializer list contains braced initializers, which in turn prevents the line formatter from finding a solution. In this commit we exclude colons that are a constructor initializer colon from consideration of nested block inlining. Fixes #97242. Fixes #81822.
6 days[clang-format] Fix a bug in `BreakBeforeBinaryOperators: All` (#149695)Owen Pan1-0/+1
Fixes #149520
2025-06-29[clang-format] Make EndsInComma in ContinuationIndenter consistent (#146256)Owen Pan1-8/+9
2025-06-15[clang-format][NFC] Clean up DisallowLineBreaks lambda (#144255)Owen Pan1-36/+42
See also https://github.com/llvm/llvm-project/pull/141576/files#r2141808121
2025-06-09[clang-format] Parse JSON outermost l_brace as braced list brace (#143327)Owen Pan1-1/+0
See https://github.com/llvm/llvm-project/issues/65400#issuecomment-2922181979.
2025-05-19[clang-format] Fix the indent of StartOfName after AttributeMacro (#140361)Owen Pan1-1/+3
Fix #139510
2025-04-12[clang-format] Wrap and indent lambda braces in GNU style (#135479)Owen Pan1-1/+10
Fix #133135
2025-04-12[clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (#135466)Owen Pan1-7/+7
Also remove redundant name qualifiers format::, FormatStyle::, and LanguageKind::.
2025-03-05[clang-format][NFC] Use better names for a couple of data membersOwen Pan1-1/+1
2025-03-03[clang-format] Fix a bug in wrapping function return type (#129374)Owen Pan1-0/+4
Fixes #113766
2025-02-27[clang-format] Change BracedInitializerIndentWidth to int (#128988)Owen Pan1-3/+3
Fixes #108526
2025-02-20[clang-format] Fix a bug in BCIS_AfterColon and `ColumnLimit: 0` (#127964)Owen Pan1-3/+2
Fixes #127622
2025-02-06[clang-format] Add BreakBeforeTemplateCloser option (#118046)leijurv1-6/+18
In clang-format, multiline templates have the `>` on the same line as the last parameter: ```c++ template < typename Foo, typename Bar> void foo() { ``` I would like to add an option to put the `>` on the next line, like this: ```c++ template < typename Foo, typename Bar > void foo() { ``` An example of a large project that uses this style is NVIDIA's CUTLASS, here is an example: https://github.com/NVIDIA/cutlass/blob/main/include/cutlass/epilogue/dispatch_policy.hpp#L149-L156 My reasoning is that it reminds me of this style of braces: ```c++ if (foo()) { bar(); baz();} ``` Most people agree this is better: ```c++ if (foo()) { bar(); baz(); } ``` --------- Co-authored-by: Owen Pan <owenpiano@gmail.com>
2025-01-30[clang-format] Fix mismatched break in BlockIndent (#124998)Gedare Bloom1-0/+7
Near the ColumnLimit a break could be inserted before a right parens with BlockIndent without a break after the matching left parens. Avoid these hanging right parens by disallowing breaks before right parens unless there was a break after the left parens. Fixes #103306
2025-01-17[clang-format] Fix option `BreakBinaryOperations` for operator `>>` (#122282)Ander1-0/+1
Fixes #106228.
2024-12-18[clang-format] Don't change breaking before CtorInitializerColon (#119522)Owen Pan1-3/+2
Don't change breaking before CtorInitializerColon with `ColumnLimit: 0`. Fixes #119519.
2024-12-17[clang-format] Detect nesting in template strings (#119989)Gedare Bloom1-1/+3
The helper to check if a token is in a template string scans too far backward. It should stop if a different scope is found. Fixes #107571
2024-11-25[clang-format][NFC] Remove a pointer in ContinuationIndenterOwen Pan1-10/+7
2024-10-11[clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments ↵Iuri Chaer1-2/+2
without breaking internal structure (think Doxygen). (#96804) * Convert `ReflowComments` from boolean into a new `enum` which can take on the value `RCS_Never`, `RCS_IndentOnly`, or `RCS_Always`. The first one is equivalent to the old `false`, the third one is `true`, and the middle one means that multiline comments should only have their indentation corrected, which is what Doxygen users will want. * Preserve backward compatibility while parsing `ReflowComments`.
2024-09-22[clang-format] Fix regression with BlockIndent of Braced Initializers (#108717)Gedare Bloom1-0/+7
Fixes #73584.
2024-09-18[clang-format] Fix regression in BAS_AlwaysBreak for-await (#108634)Gedare Bloom1-1/+2
Fixes #108589.
2024-09-11[clang-format] Fix regressions in BAS_AlwaysBreak (#107506)Owen Pan1-3/+11
Fixes #107401. Fixes #107574.
2024-08-28[clang-format] Revert "[clang-format][NFC] Delete TT_LambdaArrow (#70… ↵Owen Pan1-6/+4
(#105923) …519)" This reverts commit e00d32afb9d33a1eca48e2b041c9688436706c5b and adds a test for lambda arrow SplitPenalty. Fixes #105480.
2024-08-24[clang-format] Treat new expressions as simple functions (#105168)kadir çetinkaya1-0/+9
ccae7b461be339e717d02f99ac857cf0bc7d17f improved handling for nested calls, but this resulted in a lot of changes near `new` expressions. This patch tries to restore previous behavior around new expressions, by treating them as simple functions, which seem to align with the concept. Fixes https://github.com/llvm/llvm-project/issues/105133.
2024-08-22[clang-format] Change BinPackParameters to enum and add AlwaysOnePerLine ↵Tom1-22/+5
(#101882) Related issues that have requested this feature: #51833 #23796 #53190 Partially solves - this issue requests is for both arguments and parameters
2024-08-16[clang-format] Adjust requires clause wrapping (#101550) (#102078)Nathan Sidwell1-0/+1
Address #101550 by adding OwnLineWithBrace option for RequiresClausePosition. This permits placing a following '{' on the same line as the requires clause. Thus, instead of: ``` bool Foo () requires(true) { return true; } ``` we have: ``` bool Foo () requires(true) { return true; } ``` If the function body is empty, we'll get: ``` bool Foo () requires(true) {} ``` I attempted to get a line break between the open and close braces, but failed. Perhaps that's fine -- it's rare and only happens in the empty body case.
2024-08-10[clang-format] Add BreakBinaryOperations configuration (#95013)Ameer J1-1/+33
By default, clang-format packs binary operations, but it may be desirable to have compound operations be on individual lines instead of being packed. This PR adds the option `BreakBinaryOperations` to break up large compound binary operations to be on one line each. This applies to all logical and arithmetic/bitwise binary operations Maybe partially addresses #79487 ? Closes #58014 Closes #57280
2024-07-24[clang-format] Improve BlockIndent at ColumnLimit (#93140)Gedare Bloom1-3/+35
Fixes #55731 The reported formatting problems were related to ignoring deep nesting of "simple" functions (causing #54808) and to allowing the trailing annotation to become separated from the closing parens, which allowed a break to occur between the closing parens and the trailing annotation. The fix for the nesting of "simple" functions is to detect them more carefully. "Simple" was defined in a comment as being a single non-expression argument. I tried to stay as close to the original intent of the implementation while fixing the various bad formatting reports. In the process of fixing these bugs, some latent bugs were discovered related to how JavaScript Template Strings are handled. Those are also fixed here. --------- Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-06-10[clang-format] Fix a bug in indenting lambda trailing arrows (#94560)c8ef1-0/+5
Closes #94181
2024-06-06[clang-format] Fix a bug in `AlignAfterOpenBracket: DontAlign` (#94561)Owen Pan1-1/+1
Fixes #94555.
2024-05-11[clang] Use StringRef::operator== instead of StringRef::equals (NFC) (#91844)Kazu Hirata1-1/+1
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 24 under clang/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-04-12[clang-format] Fix a regression in ContinuationIndenter (#88414)Owen Pan1-1/+7
Commit d06b92391513 caused a regression that breaks after a block comment adjacent to a function paramter that follows. Fixes #86573.
2024-03-19Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"Owen Pan1-0/+9
This reverts commit b92d6dd704d789240685a336ad8b25a9f381b4cc. See github.com/llvm/llvm-project/commit/b92d6dd704d7#commitcomment-139992444 We should use a tool like Visual Studio to clean up the headers.
2024-03-19Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions ↵Owen Pan1-7/+5
(#84599)" This reverts c3a1eb6207d8 (and the related commit f3c5278efa3b) which makes cleanupAroundReplacements() no longer thread-safe.
2024-03-19[clang-format] Add Options to break inside the TableGen DAGArg. (#83149)Hirofumi Nakamura1-2/+17
Add two options to control the line break inside TableGen DAGArg. - TableGenBreakInsideDAGArg - TableGenBreakingDAGArgOperators
2024-03-16[clang-format][NFC] Delete 100+ redundant #include lines in .cpp filesOwen Pan1-9/+0
2024-03-14Reland [clang-format][NFC] Eliminate the IsCpp parameter in all functions ↵Owen Pan1-5/+7
(#84599) Initialize IsCpp in LeftRightQualifierAlignmentFixer ctor.
2024-03-14Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions" ↵Mehdi Amini1-7/+5
(#85353) Reverts llvm/llvm-project#84599 This broke the presubmit bot.
2024-03-14[clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599)Owen Pan1-5/+7
2024-02-19[clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda ↵rmarker1-4/+12
brace wrapping. (#81848) Fix an issue where the lambda body left brace could sometimes fail to be wrapped when AllowShortLambdasOnASingleLine is enabled. Now, when BraceWrapping.BeforeLambdaBody is enabled, if the brace is not wrapped, we prevent breaks in the lambda body. Resolves #81845
2024-02-16[clang-format] Support of TableGen basic format restrictions. (#81611)Hirofumi Nakamura1-2/+12
- Allow/force to break the line or not. - Allow/force to insert space or not.
2024-02-14[clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (#81591)rmarker1-3/+3
Complete the switch from "AlwaysBreakAfterReturnType" to "BreakAfterReturnType".
2024-02-09[clang-format][NFC] Drop "Always" in "AlwaysBreakTemplateDeclarations"Owen Pan1-3/+2
2024-02-07[clang-format] Add Leave to AlwaysBreakTemplateDeclarations (#80569)Owen Pan1-1/+4
Closes #78067.
2024-02-06[clang-format] Handle generic selections inside parentheses (#79785)sstwcw1-2/+5
new ```C while (_Generic(x, // long: x)(x) > x) { } while (_Generic(x, // long: x)(x)) { } ``` old ```C while (_Generic(x, // long: x)(x) > x) { } while (_Generic(x, // long: x)(x)) { } ``` In the first case above, the second line previously aligned to the open parenthesis. The 4 spaces did not get added by the fallback line near the end of getNewLineColumn because there was already some indentaton. Now the spaces get added explicitly. In the second case above, without the fake parentheses, the second line did not respect the outer parentheses, because the LastSpace field did not get set without the fake parentheses. Now the indentation of the outer level is used instead.
2024-02-04[clang-format] Add Automatic and ExceptShortType options for ↵rmarker1-3/+11
AlwaysBreakAfterReturnType. (#78011) The RTBS_None option in Clang-format avoids breaking after a short return type. However, there was an issue with the behaviour in that it wouldn't take the leading indentation of the line into account. This meant that the behaviour wasn't applying when intended. In order to address this situation without breaking the existing formatting, RTBS_None has been deprecated. In its place are two new options for AlwaysBreakAfterReturnType. The option RTBS_Automatic will break after the return type based on PenaltyReturnTypeOnItsOwnLine. The option RTBS_ExceptShortType will take the leading indentation into account and prevent breaking after short return types. This allows the inconsistent behaviour of RTBS_None to be avoided and users to decide whether they want to allow breaking after short return types or not. Resolves #78010
2024-01-22[clang-format]: Fix formatting of if statements with BlockIndent (#77699)Gedare Bloom1-7/+17
A bug with BlockIndent prevents line breaks within if (and else if) clauses. While fixing this bug, it appears that AlignAfterOpenBracket is not designed to work with loop and if statements, but AlwaysBreak works on if clauses. The documentation and tests are not clear on whether or not this behavior is intended. This PR preserves the `AlwaysBreak` behavior on `if` clauses without supporting `BlockIndent` on `if` clauses to avoid regressions while fixing the bug. It may be reasonable to create an explicit option for alignment of if (and loop) clauses intentionally for both `AlwaysBreak` and `BlockIndent` Fixes #54663. Migrated from Differential Revision: https://reviews.llvm.org/D154755 See more discussion there. Addressed last open comment from the rev about refactoring the complex conditional logic involved with the `AlignAfterOpenBracket` line break behavior.
2024-01-22[clang-format] Fix a bug in ContinuationIndenter (#78921)Owen Pan1-1/+2
Fixes #76991.
2024-01-22[clang-format] Don't confuse initializer equal signs in for loops (#77712)Emilia Kond1-1/+3
clang-format has logic to align declarations of multiple variables of the same type, aligning them at the equals sign. This logic is applied in for loops as well. However, this alignment logic also erroneously affected the equals signs of designated initializers. This patch forbids alignment if the token 2 tokens back from the equals sign is a designated initializer period. Fixes https://github.com/llvm/llvm-project/issues/73902
2024-01-17[clang-format] TableGen multi line string support. (#78032)Hirofumi Nakamura1-0/+3
Support the handling of TableGen's multiline string (code) literal. That has the form, [{ this is the string possibly with multi line... }]