aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format
AgeCommit message (Collapse)AuthorFilesLines
5 hours[clang-format] Fix a bug in `DerivePointerAlignment: true` (#150744)Owen Pan1-17/+29
This effectively reverts a4d4859dc70c046ad928805ddeaf8fa101793394 which didn't fix the problem that `int*,` was not counted as "Left" alignment. Fixes #150327
3 days[clang-format] Google Style: disable DerivePointerAlignment. (#149602)James Y Knight1-1/+1
The [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html#Pointer_and_Reference_Expressions) is being changed to specify that spaces should go after the asterisk/ampersand, rather than permitting either before or after on a file-by-file basis. The new requirement is: > When referring to a pointer or reference (variable declarations or > definitions, arguments, return types, template parameters, etc.), > you must not place a space before the asterisk/ampersand. Use a > space to separate the type from the declared name (if present). The [Google ObjC style](https://google.github.io/styleguide/objcguide.html) is silent on this matter, but the de-facto style is not being modified at this time. So, keep DerivePointerAlignment enabled for ObjC language mode.
4 days[clang-format] Fix a bug in `DerivePointerAlignment: true` (#150387)Owen Pan1-2/+3
Fixes #150327
4 days[clang-format] Add AfterNot to SpaceBeforeParensOptions (#150367)Owen Pan2-1/+3
Closes #149971
4 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][NFC] Clean up around StringRef initializations (#149765)Owen Pan4-9/+9
Consistently use `constexpr StringRef Code("string literal");`.
7 days[clang-format] Remove code related to trigraphs (#148640)sstwcw1-24/+11
When reviewing #147156, the reviewers pointed out that we didn't need to support the trigraph. The code never handled it right. In the debug build, this kind of input caused the assertion in the function `countLeadingWhitespace` to fail. The release build without assertions outputted `?` `?` `/` separated by spaces. ```C #define A ??/ int i; ``` This is because the code in `countLeadingWhitespace` assumed that the underlying lexer recognized the entire `??/` sequence as a single token. In fact, the lexer recognized it as 3 separate tokens. The flag to make the lexer recognize trigraphs was never enabled. This patch enables the flag in the underlying lexer. This way, the program now either turns the trigraph into a single `\` or removes it altogether if the line is short enough. There are operators like the `??=` in C#. So the flag is not enabled for all input languages. Instead the check for the token size is moved from the assert line into the if line. The problem was introduced by my own patch 370bee480139 from about 3 years ago. I added code to count the number of characters in the escape sequence probably just because the block of code used to have a comment saying someone should add the feature. Maybe I forgot to enable assertions when I ran the code. I found the problem because reviewing pull request 145243 made me look at the code again.
7 days[clang-format] Fix a bug in `BreakBeforeBinaryOperators: All` (#149695)Owen Pan1-0/+1
Fixes #149520
10 days[clang-format] Fix a regression of annotating PointerOrReference (#149039)Owen Pan1-3/+7
Fixes #149010
11 days[clang-format] Add IgnoreExtension to SortIncludes (#137840)Daan De Meyer1-16/+29
Sorting by stem gives nicer results when various header file names are substrings of other header file names. For example, a CLI application with a main header named analyze.h and an analyze-xxx.h header for each subcommand currently will always put analyze.h last after all the analyze-xxx.h headers, but putting analyze.h first instead is arguably nicer to read. TLDR; Instead of ``` #include "analyze-blame.h" #include "analyze.h" ``` You'd get ``` #include "analyze.h" #include "analyze-blame.h" ``` Let's allow sorting by stem instead of full path by adding IgnoreExtension to SortIncludes.
2025-07-13[clang-format][NFC] Simplify some logic in BreakableLineCommentSection (#148324)Owen Pan1-6/+4
2025-07-13[clang-format] Add MacrosSkippedByRemoveParentheses option (#148345)Owen Pan7-9/+22
This allows RemoveParentheses to skip the invocations of function-like macros. Fixes #68354. Fixes #147780.
2025-07-11Follow up on #147623Owen Pan1-1/+0
2025-07-10[clang-format] Split line comments separated by backslashes (#147648)Owen Pan1-9/+12
Fixes #147341
2025-07-10[clang-format][NFC] Replace a function with StringRef::contains (#146245)Owen Pan1-13/+1
2025-07-09Address a handful of C4146 compiler warnings where literals can be replaced ↵Alex Sepkowski1-10/+17
with std::numeric_limits (#147623) This PR addresses instances of compiler warning C4146 that can be replaced with std::numeric_limits. Specifically, these are cases where a literal such as '-1ULL' was used to assign a value to a uint64_t variable. The intent is much cleaner if we use the appropriate std::numeric_limits value<Type>::max() for these cases. Addresses #147439
2025-07-06[clang-format][NFC] Use `empty()` instead of comparing size() to 0 or 1Owen Pan3-4/+4
2025-07-06[clang-format][NFC] Replace size() with empty() (#147164)Owen Pan5-15/+13
2025-07-05[clang-format] Propagate `LeadingEmptyLinesAffected` when joining lines ↵Eric Li1-1/+3
(#146761) Before this commit, when `LineJoiner` joins a line with affected leading whitespace, it would drop the knowledge of this entirely. However, when the `AffectedRangeManager` is computing the affected lines, the leading empty whitespace lines are potentially considered for non-first tokens in the `AnnotatedLine`. This causes a discrepancy in behavior when an `AnnotatedLine` is put together from joining multiple lines versus when it is not. We change `LineJoiner::join` to follow `AffectedRangeManager`'s logic, considering the leading whitespace when determining `Affected` for a token. https://github.com/llvm/llvm-project/blob/a63f57262898588b576d66e5fd79c0aa64b35f2d/clang/lib/Format/AffectedRangeManager.cpp#L111-L130 Fixes #138942.
2025-06-29[clang-format] Make EndsInComma in ContinuationIndenter consistent (#146256)Owen Pan1-8/+9
2025-06-28[clang-format] Fix a bug in `ReflowComments: Always` (#146202)Owen Pan1-2/+1
Fixes #39150
2025-06-26[clang-format][NFC] Remove `\brief` from comments (#145853)Owen Pan3-15/+14
This was done before in https://reviews.llvm.org/D46320
2025-06-25[clang-format][NFC] Remove a redundant check for nullOwen Pan1-1/+1
Missed by #145686
2025-06-25[clang-format] Handle Trailing Whitespace After Line Continuation (P2223R2) ↵Naveen Seth Hanig1-9/+21
(#145243) Fixes #145226. Implement [P2223R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2223r2.pdf) in clang-format to correctly handle cases where a backslash '\\' is followed by trailing whitespace before the newline. Previously, `clang-format` failed to properly detect and handle such cases, leading to misformatted code. With this, `clang-format` matches the behavior already implemented in Clang's lexer and `DependencyDirectivesScanner.cpp`, which allow trailing whitespace after a line continuation in any C++ standard.
2025-06-25Remove unneeded checks for null; NFC (#145686)Aaron Ballman1-4/+1
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[clang-format] Improve QualifierAlignment in guessing macros (#145468)Owen Pan1-7/+18
Fixes #145388
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-14[clang-format] Fix a bug in annotating braces (#144095)Owen Pan1-1/+1
Stop looking for function decls after hitting a BK_BracedInit brace. Fixes #144057.
2025-06-11[Format] Use llvm::min_element (NFC) (#143725)Kazu Hirata1-4/+4
llvm::min_elements allows us to pass a range.
2025-06-09[clang-format] Parse JSON outermost l_brace as braced list brace (#143327)Owen Pan2-2/+1
See https://github.com/llvm/llvm-project/issues/65400#issuecomment-2922181979.
2025-06-06[clang-format] Handle function decls with MS calling conventions (#143083)Owen Pan1-1/+9
2025-06-05[clang-format] More consumeToken() cleanup (#143063)Owen Pan1-26/+21
Similar to #142104
2025-06-05[clang-format] Handle requires clause following a pointer type (#142893)Owen Pan1-0/+1
Fix #142818
2025-06-02[clang-format] Correctly annotate token-pasted function decl names (#142337)Owen Pan1-0/+2
Fix #142178
2025-06-01Revert "[clang-format] Handle token-pasted function decl names (#142251)"Owen Pan1-6/+1
This reverts commit 29f79ea3c59649f7686a09845665660c25ca3f9b which caused a regression. See https://github.com/llvm/llvm-project/pull/142251#issuecomment-2928718530.
2025-05-31[Format] Remove unused includes (NFC) (#142296)Kazu Hirata9-18/+0
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[clang-format] Handle token-pasted function decl names (#142251)Owen Pan1-1/+6
Fix #142178
2025-05-30[clang-format] Handle bit-field colon of non-numeric-constant size (#142110)Owen Pan1-1/+3
Fix #142050
2025-05-30[clang-format][NFC] Clean up AnnotatingParser::consumeToken() (#142104)Owen Pan1-58/+43
2025-05-28[clang-format] Handle .h files for LK_C and LK_ObjC (#141714)Owen Pan1-5/+13
Fix #137792
2025-05-26[Format] Use llvm::count_if (NFC) (#141518)Kazu Hirata1-3/+2
2025-05-25[clang-format] Handle Java text blocks (#141334)Owen Pan2-0/+34
Fix #61954
2025-05-23[clang-format][NFC] FormatTokenLexer.cpp cleanup (#141202)Owen Pan1-39/+26
2025-05-21[clang] Use llvm::find_if (NFC) (#140983)Kazu Hirata1-3/+3
2025-05-21[clang-format][NFC] Minor efficiency cleanup (#140835)Owen Pan2-18/+10
2025-05-20[clang-format] Handle raw string literals containing JSON code (#140666)Owen Pan1-2/+4
Fix #65400
2025-05-19[clang-format][NFC] Upgrade SortIncludes option to a struct (#140497)Owen Pan1-12/+22
This allows adding other suboptions e.g. IgnoreExtension in #137840.
2025-05-19[clang-format] Merge short inline function in macro definition body (#140366)Owen Pan1-2/+2
Fix #62356
2025-05-19[clang-format] Fix the indent of StartOfName after AttributeMacro (#140361)Owen Pan1-1/+3
Fix #139510
2025-05-18[clang] Use llvm::unique (NFC) (#140459)Kazu Hirata1-5/+4