1463 Commits

Author SHA1 Message Date
owenca
2302110838
[clang-format] Don't annotate C compound literal r_paren (#180436)
Fixes #180179
2026-02-10 06:22:13 +00:00
Vikas Patel
90cc5a4618
[clang-format] Add ObjCSpaceBeforeMethodDeclColon option to control space before Objective-C method return type (#170579)
[clang-format] Add ObjCSpaceBeforeMethodDeclColon option to control
space before Objective-C method return type

This patch introduces the ObjCSpaceBeforeMethodDeclColon style option,
allowing users to add or remove a space between the '-'/'+' and the
return type in Objective-C method declarations (e.g., '- (void)method'
vs '-(void)method').

Includes documentation and unit tests.
2026-01-27 19:55:20 +00:00
Owen Pan
79c11ef40c [clang-format][NFC] Remove redundant checking for null pointer
See https://github.com/llvm/llvm-project/pull/143194#discussion_r2674008700
2026-01-09 19:58:22 -08:00
owenca
347c6006f4
[clang-format] Fix a crash in formatting unbalanced angle brackets (#173456)
Fixes #173382
2025-12-25 08:23:23 +00:00
Björn Schäpers
0812f41cd6
[clang-format] Don't crash on incomplete template declaration (#173433) 2025-12-24 13:32:25 +00:00
Ben Dunkin
0bac8f1729
[clang-format] Handle templates in qualified typenames (#143194)
This fixes the `SpaceBeforeParensOptions.AfterFunctionDeclarationName`
and `SpaceBeforeParensOptions.AfterFunctionDefinitionName` options not
adding spaces when a template type's constructor or destructor is
forward declared or defined outside of the type definition.

Attribution Note - I have been authorized to contribute this change on
behalf of my company: ArenaNet LLC
2025-12-09 20:47:38 -08:00
Daan De Meyer
7b186e4bf0
[clang-format] Fix designated initializer detection (#169228)
Currently, in the following snippet, the second designated initializer
is incorrectly detected as an OBJC method expr. Fix that and a test to
make sure we don't regress.

```
Foo foo[] = {[0] = 1, [1] = 2};
```
2025-11-24 20:26:07 +01:00
owenca
02a997cf36
[clang-format] Handle import when used as template function name (#169279)
Fixes #149960
2025-11-24 00:00:10 -08:00
owenca
a83e09a788
[clang-format] Handle && in requires clause in requires requires (#169207)
Fixes #152266
2025-11-23 10:08:37 +00:00
owenca
3c0d4aa601
[clang-format] Handle static_assert more accurately (#166042)
Used test cases from #165631.
2025-11-02 22:35:50 -08:00
Gedare Bloom
8067b5cff7
[clang-format] Add BreakAfterOpenBracket* and BreakBeforeCloseBracket* (#108332)
Replace the `AlwaysBreak` and `BlockIndent` suboptions of
`AlignAfterOpenBracket` with new style options `BreakAfterOpenBracket*`
and `BreakBeforeCloseBracket*` for `*` in `BracedList` for braced list
initializers, `if` for if conditional statements, `Loop` for loop
control statements (for/while), `Switch` for switch statements, and
`Function` for function calls/declarations/definitions.

Deprecates `AlwaysBreak` and `BlockIndent`.
 
Fixes #67738 
Fixes #79176 
Fixes #80123 
Fixes #151844
2025-10-30 20:24:44 +01:00
owenca
3fc24a282a
[clang-format] Fix a bug in annotating class member names (#165351)
For declarations like `Type* ::Class::member...`, `Class` was not
annotated as `TT_StartOfName`as it should be. This prevented `member`
from being updated to `TT_FunctionDeclarationName` if `member` was a
function name.

Fixes #164866
2025-10-28 20:16:24 -07:00
Owen Pan
44601d1a7a Reapply "Reapply "[clang-format] Annotate ::operator and Foo::operator… (#165038)
This reverts commit bd27abcceedfc60f4598124aa022cd0b766da3d8.

See https://github.com/llvm/llvm-project/pull/164670#issuecomment-3445926724
2025-10-24 23:01:47 -07:00
PiJoules
bd27abccee
Revert "Reapply "[clang-format] Annotate ::operator and Foo::operator… (#165038)
… correctly" (#164670)"

This reverts commit 50ca1f407801cd268a1c130b9576dfb51fe7f392.

Reverting because this leads to the bug on ToT described in
https://github.com/llvm/llvm-project/issues/164866. The original fix
addresses an old regression which we'd still like to land eventually.
See the discussion in https://github.com/llvm/llvm-project/pull/164670
for more context.
2025-10-24 14:36:23 -07:00
sstwcw
53b9441f53
[clang-format] Break the line within ObjC @selector (#164674)
after, with style `{ColumnLimit: 60}`

```Objective-C
[objectName
    respondsToSelector:
        @selector(
            somelonglonglonglongnameeeeeeee:
            loooooooooanotherlonglonglonglongnametopush:
            otherlongnameforlimit:)];
```

before

```Objective-C
[objectName
    respondsToSelector:
        @selector(
            somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)];
```

Fixes #164574.

The stuff inside the parentheses got a new type in 2a059042882ed. I
neglected to add it to the logic for breaking lines.
2025-10-23 13:17:36 +00:00
Owen Pan
50ca1f4078 Reapply "[clang-format] Annotate ::operator and Foo::operator correctly" (#164670)
This reverts commit 99abda7b02c9d6ba8b996867d2de624815ace1ce.

See https://github.com/llvm/llvm-project/pull/164670#issuecomment-3435040114
2025-10-22 21:37:36 -07:00
PiJoules
99abda7b02
Revert "[clang-format] Annotate ::operator and Foo::operator correctly" (#164670)
Reverts llvm/llvm-project#164048

This led to a regression in clang-format where a space gets added in
between the parameter type and `&`. For example, this

```
::test_anonymous::FunctionApplication& ::test_anonymous::FunctionApplication::operator=(const ::test_anonymous::FunctionApplication& other) noexcept {
```

becomes

```
::test_anonymous::FunctionApplication& ::test_anonymous::FunctionApplication::operator=(const ::test_anonymous::FunctionApplication & other) noexcept {
```
2025-10-22 18:00:26 +00:00
owenca
f0720363d3
[clang-format][NFC] Annotate attribute squares more effectively (#164052)
Annotate left/right attribute squares distinctively and only annotate
the outer pair of C++ attribute squares.
2025-10-19 11:38:08 -07:00
Björn Schäpers
cf28a476fb
[clang-format] Remove special handling of comments after brace/paren (#71672)
Fixes http://llvm.org/PR55487 (#55487)

The code did not match the documentation about Cpp11BracedListStyle.
Changed handling of comments after opening braces, which are supposedly
function call like to behave exactly like their parenthesis counter
part.
2025-10-18 22:25:28 +00:00
owenca
3bb9d4a24e
[clang-format] Annotate ::operator and Foo::operator correctly (#164048)
This effectively reverts commit b5f6689dc93216f9272e790e787548cf29250566
and fixes #111011 more narrowly.

Fixes #160513
2025-10-18 12:13:25 -07:00
sstwcw
2a05904288
[clang-format] Keep the ObjC selector name and @selector together (#160739)
Fixes #36459.

after

```Objective-C
- (void)test {
  if ([object
          respondsToSelector:@selector(
                                 selectorNameThatIsReallyLong:param1:param2:)])
    return;
}
```

before

```Objective-C
- (void)test {
  if ([object respondsToSelector:@selector
              (selectorNameThatIsReallyLong:param1:param2:)])
    return;
}
```

Before this patch, the `ObjCMethodExpr` type was assigned to many kinds
of tokens. The rule for allowing breaking the line before the colon on
line TokenAnnotator.cpp:6289 was intended for method declarations and
calls. It matched the parenthesis following `@selector` by mistake. To
fix the problem, this patch adds a new type for `@selector`. Most of the
special things in the code related to the old type is intended for other
constructs. So most of the code related to the old type is not changed
in this patch.
2025-10-03 20:40:48 +00:00
Björn Schäpers
847e1e1890
[clang-format][NFC] Introduce isNoneOf (#161021)
And apply throughout the code base.
2025-10-02 20:52:45 +02:00
owenca
56d920d586
[clang-format] Fix a bug in wrapping { after else (#161048)
Fixes #160775
2025-09-29 21:11:20 -07:00
owenca
4edda3d78c
[clang-format] Fix bugs in annotating arrows and square brackets (#160973)
Fixes #160518
2025-09-27 21:29:25 -07:00
sstwcw
a0c75a9009
[clang-format] Align within the level with Cpp11BracedListStyle disabled (#159140)
When the style is
`{AlignConsecutiveDeclarations: true, Cpp11BracedListStyle: false}`, the
program would sometimes align the lambda body with the outside. Like
this.

```C++
const volatile auto result{ []() {
  const auto        something = 1;
  return 2;
} };
```

This patch stops it.  Now the output looks like this.

```C++
const volatile auto result{ []() {
  const auto something = 1;
  return 2;
} };
```

Fixes #53699.

The problem was with how the `AlignTokenSequence` function tracked
levels. The stack was pushed once when a token was more nested than the
previous one. It was popped once when a token was less nested than the
previous one. With the option `Cpp11BracedListStyle` disabled, the `[`
token was deeper than the previous token by 2 levels. Both its
indentation level and nesting level were more than that of the previous
one. But the stack was only pushed once. The following tokens popped the
2 levels separately. The function treated the body of the lambda
expression as on the same level as the outside.

The problem is fixed this way. The function `AlignTokens` which calls
the function `AlignTokenSequence` already uses a simpler and more robust
way to track levels. It remembers the outermost level it should align.
It compares the token's level with the outermost level. It does not need
a stack. So it is immune to the problem. This patch makes the function
`AlignTokenSequence` take as a parameter the indices of the tokens
matched by the function `AlignTokens`. This way it does not have to
contain the logic again.

Now the function `AlignTokenSequence` only aligns tokens already matched
by the function `AlignTokens`. It is easy to see that the assertion on
line 453 holds. The workaround on line 354 is not needed any more. The
test on line 20310 added at the same time as the assertion ensures that
the assertion hold.

The stack in the function `AlignTokenSequence` is kept for now. It is
still used to figure out when things inside a level should move along
with the outer level. Since the stack has the problem, the developer
plans to move the logic into token annotator. It already uses a stack.
2025-09-25 16:46:43 +00:00
owenca
583256d165
[clang-format] Add AllowBreakBeforeQtProperty option (#159909)
The test cases are adapted from #131605.
2025-09-22 00:07:14 -07:00
Gedare Bloom
7dd2f1cc10
[clang-format] Add IndentPPDirectives Leave option (#139750)
Allow an option to leave preprocessor directive indenting as-is. This
simplifies handling mixed styles of CPP directive indentation.

Fixes #38511
2025-09-14 13:47:06 -07:00
Hirofumi Nakamura
bfc8411082
[clang-format] Fix TableGen nested DAGArg format (#155837)
Fixes https://github.com/llvm/llvm-project/issues/154634. 
Allow inserting space before DAGArg's opener paren when nested.
2025-08-31 16:08:34 +09:00
owenca
c62a5bf52d
[clang-format] Correctly annotate RequiresExpressionLBrace (#155773)
Fixes #155746
2025-08-28 07:40:42 -07:00
owenca
6cfedea492
[clang-format] Add SpaceInEmptyBraces option (#153765)
Also set it to SIEB_Always for WebKit style.

Closes #85525.
Closes #93635.
2025-08-17 12:56:22 -07:00
owenca
5e57a10f50
[clang-format] Allow breaking before bit-field colons (#153529)
Fixes #153448
2025-08-17 12:54:23 -07:00
owenca
9a692e0f94
[clang-format] Don't annotate class property specifiers as StartOfName (#153525)
Fixes #153443
2025-08-17 12:53:57 -07:00
Owen Pan
d696f8104e
[clang-format][NFC] Maximize usage of isOneOf() in TokenAnnotator (#151658)
Also make a StringRef literal `static constexpr`.
2025-08-02 12:18:04 -07:00
Owen Pan
97c953406d
[clang-format] Add AfterNot to SpaceBeforeParensOptions (#150367)
Closes #149971
2025-07-24 09:38:43 -07:00
Owen Pan
a8f5e9ed6b
[clang-format] Fix a regression of annotating PointerOrReference (#149039)
Fixes #149010
2025-07-17 21:43:43 -07:00
Owen Pan
c384ec431d
[clang-format] Add MacrosSkippedByRemoveParentheses option (#148345)
This allows RemoveParentheses to skip the invocations of function-like
macros.

Fixes #68354.
Fixes #147780.
2025-07-13 14:29:51 -07:00
Owen Pan
117ed65c07 [clang-format][NFC] Remove a redundant check for null
Missed by #145686
2025-06-25 20:10:53 -07:00
Aaron Ballman
01174ff2ba
Remove unneeded checks for null; NFC (#145686)
At the start of the case for `tok::colon`, we do an early return if
`Prev` is null. Nothing else within that case modifies the value of
`Prev`, so the checks for null are unnecessary and were confusing
static analysis tools.
2025-06-25 09:04:36 -04:00
Owen Pan
2e7fbb94bc
[clang-format] Fix a bug in annotating braces (#144095)
Stop looking for function decls after hitting a BK_BracedInit brace.

Fixes #144057.
2025-06-14 00:21:39 -07:00
Owen Pan
0c495ce9c4
[clang-format] Handle function decls with MS calling conventions (#143083) 2025-06-06 20:43:35 -07:00
Owen Pan
eb71fdde57
[clang-format] More consumeToken() cleanup (#143063)
Similar to #142104
2025-06-05 23:36:43 -07:00
Owen Pan
7bf5862dbf
[clang-format] Correctly annotate token-pasted function decl names (#142337)
Fix #142178
2025-06-02 13:35:27 -07:00
Owen Pan
c5cce4861c Revert "[clang-format] Handle token-pasted function decl names (#142251)"
This reverts commit 29f79ea3c59649f7686a09845665660c25ca3f9b which caused a regression.

See https://github.com/llvm/llvm-project/pull/142251#issuecomment-2928718530.
2025-06-01 23:32:00 -07:00
Kazu Hirata
dfaa66281a
[Format] Remove unused includes (NFC) (#142296)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-31 19:00:34 -07:00
Owen Pan
29f79ea3c5
[clang-format] Handle token-pasted function decl names (#142251)
Fix #142178
2025-05-31 11:11:00 -07:00
Owen Pan
4851886693
[clang-format] Handle bit-field colon of non-numeric-constant size (#142110)
Fix #142050
2025-05-30 18:51:01 -07:00
Owen Pan
3f0a5305b4
[clang-format][NFC] Clean up AnnotatingParser::consumeToken() (#142104) 2025-05-30 01:51:23 -07:00
Owen Pan
d5d8d8ac76
[clang-format][NFC] Minor efficiency cleanup (#140835) 2025-05-21 20:24:56 -07:00
Filip Milosevic
5df01abe19
[clang-format] Add SpaceAfterOperatorKeyword option (#137610)
Add SpaceAfterOperatorKeyword option to clang-format
2025-05-07 22:47:56 -07:00
Owen Pan
fa09d031d3
[clang-format] Correctly annotate ObjC * __autoreleasing * (#138799)
Fix #138484
2025-05-07 22:41:57 -07:00