1434 Commits

Author SHA1 Message Date
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
Owen Pan
0e75810456
[clang-format] Fix a bug in annotating binary operator && (#138633)
Fix #138485
2025-05-06 19:37:54 -07:00
Owen Pan
b1e6c4b435
[clang-format] Correctly annotate C# nullable value type ? (#138631)
Fix #78666
2025-05-06 19:37:26 -07:00
Owen Pan
17ea830baf
[clang-format] Don't annotate enum colon as InheritanceColon (#138440)
Fix #61156
2025-05-06 19:36:51 -07:00
Owen Pan
deec7fb42d
[clang-format] Correctly annotate tok::star in braced list (#138389)
Fix #138382
2025-05-03 14:54:48 -07:00
Owen Pan
e6d7f46ce9
[clang-format] Correctly annotate user-defined conversion function call (#137914)
Fix #137770
2025-04-30 20:08:00 -07:00
Owen Pan
d403c70ff3
[clang-format] Annotate tok::star in a*b*c as BinaryOperator (#137433)
Fix #137400
2025-04-26 12:55:00 -07:00
Owen Pan
da8f2d5242 Revert "[clang-format] Allow breaking before kw___attribute (#128623)"
This reverts commit 8fc8a84e23471fe56214e68706addc712b5a2949, which caused a
regression.

Fixes #136675.
2025-04-22 23:49:26 -07:00
Owen Pan
037657de7e
[clang-format] Correctly annotate kw_operator in using decls (#136545)
Fix #136541
2025-04-22 21:08:56 -07:00
Owen Pan
ab4c939579
[clang-format] Fix a bug in annotating TT_PointerOrReference (#136073)
Fix #135972
2025-04-18 18:12:27 -07:00
Owen Pan
9bd0c8726a
[clang-format] Fix a bug in BWACS_MultiLine (#135906)
Fix #51940
2025-04-16 18:48:10 -07:00
Owen Pan
c41ef751f8
[clang-format] Treat lambda in braced init as inline (#135520)
Fix #125430
2025-04-13 09:02:46 -07:00
Owen Pan
09c8cfe219
[clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (#135466)
Also remove redundant name qualifiers format::, FormatStyle::, and
LanguageKind::.
2025-04-12 15:04:29 -07:00
sstwcw
f7617f7f90
[clang-format] Recognize TableGen paste operator on separate line (#133722)
Formatting this piece of code made the program crash.

```
class TypedVecListRegOperand<RegisterClass Reg, int lanes, string eltsize>
    : RegisterOperand<Reg, "printTypedVectorList<" # lanes # ", '"
                                                   # eltsize # "'>">;
```

The line starting with the `#` was treated as a separate preprocessor
directive line. Then the code dereferenced a null pointer when it tried
to continue parsing the first line that did not end in a semicolon.

Now the 2 problems are fixed.
2025-04-10 12:52:02 +00:00
Owen Pan
f344838389
[clang-format] Keep the space between not and a unary operator (#135035)
Also keep the space between `not` and `::`.

Based on the
[documentation](https://releases.llvm.org/20.1.0/tools/clang/docs/ClangFormatStyleOptions.html#spaceafterlogicalnot),
it can be argued that SpaceAfterLogicalNot doesn't cover the alternative
operator `not`.

Closes #125465
2025-04-09 17:52:12 -07:00
Owen Pan
75cbb1f0fa
[clang-format][NFC] Add FormatToken::is(tok::ObjCKeywordKind) (#134973)
This allows simplification of code that checks if a token is an
Objective-C keyword.

Also, delete the following in
UnwrappedLineParser::parseStructuralElement():
- an else-after-break in the tok::at case
- the copypasted code in the tok::objc_autoreleasepool case
2025-04-09 17:49:26 -07:00
Owen Pan
d71ee7d230
[clang-format] Set C11 instead of C17 for LK_C (#134472)
Fix #134453
2025-04-05 13:35:45 -07:00
Owen Pan
d3be29642f
[clang-format] Correctly annotate pointer/reference in _Generic (#133673)
Fix #133663
2025-03-31 23:16:41 -07:00
Owen Pan
b8a0558dea
[clang-format] Fix a regression on annotating template angles (#132885)
Annotate the angles in `A<B != A>B` as template opener/closer as it's
unlikely that they are less/greater-than operators in this context.

Fix #132248
2025-03-27 00:57:17 -07:00
Owen Pan
da7f1564a8
[clang-format] Don't wrap before attributes in parameter lists (#132519)
Fix #132240
2025-03-24 19:18:13 -07:00
Owen Pan
91328dbae9
[clang-format] Correctly annotate user-defined conversion functions (#131434)
Also fix/delete existing invalid/redundant test cases.

Fix #130894
2025-03-16 16:11:39 -07:00
Owen Pan
024362f413
[clang-format] Insert a space after kw_new by default (#129634)
This effectively reverts dbc4d281bd6954362ccfc0747893ceaae842671b.

Fix #54703
2025-03-04 21:14:07 -08:00
Owen Pan
d29a1be94b
[clang-format] Don't break before *const (#128817)
Fixes #28919
2025-02-26 18:25:09 -08:00
Owen Pan
8fc8a84e23
[clang-format] Allow breaking before kw___attribute (#128623)
Fixes #74784
2025-02-25 19:44:54 -08:00
Owen Pan
0968df9c3a
[clang-format] Add the C language instead of treating it like C++ (#128287)
Closes #128120
2025-02-23 00:36:19 -08:00
Owen Pan
13de15c9c4
[clang-format] Fix a bug in annotating StartOfName (#127545)
Also ensure we can break before ClassHeadName like StartOfName.

Fixes #127470
2025-02-18 00:15:01 -08:00
Owen Pan
3063153b56
[clang-format] Fix a bug in annotating ObjCMethodSpecifier (#127159)
Fixes #58202.
2025-02-14 21:10:08 -08:00
Owen Pan
8d373ceaec
[clang-format] Handle C-style cast of member function pointer type (#126340)
Fixes #125012.
2025-02-08 23:22:33 -08:00
leijurv
d2b45ce100
[clang-format] Add BreakBeforeTemplateCloser option (#118046)
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-02-06 01:15:47 -08:00
Owen Pan
1a25bea852
[clang-format] Add ClassHeadName to help annotating StartOfName (#124891)
Fixes #124574.
2025-01-30 19:33:15 -08:00