aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format
AgeCommit message (Collapse)AuthorFilesLines
34 hours[clang-format] Fix a bug in `DerivePointerAlignment: true` (#150744)Owen Pan1-1/+6
This effectively reverts a4d4859dc70c046ad928805ddeaf8fa101793394 which didn't fix the problem that `int*,` was not counted as "Left" alignment. Fixes #150327
4 days[clang-format] Google Style: disable DerivePointerAlignment. (#149602)James Y Knight1-9/+13
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.
5 days[clang-format] Fix a bug in `DerivePointerAlignment: true` (#150387)Owen Pan1-0/+2
Fixes #150327
5 days[clang-format] Add AfterNot to SpaceBeforeParensOptions (#150367)Owen Pan2-0/+7
Closes #149971
5 days[clang-format] Stop ctor initializer from being inlined (#150361)Eric Li1-0/+10
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.
8 days[clang-format][NFC] Clean up around StringRef initializations (#149765)Owen Pan8-67/+67
Consistently use `constexpr StringRef Code("string literal");`.
8 days[clang-format] Remove code related to trigraphs (#148640)sstwcw1-0/+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.
9 days[clang-format][NFC] Delete redundant type names after FormatStyle::Owen Pan2-14/+12
9 days[clang-format] Fix a bug in `BreakBeforeBinaryOperators: All` (#149695)Owen Pan1-0/+5
Fixes #149520
12 days[clang-format] Fix a regression of annotating PointerOrReference (#149039)Owen Pan1-0/+4
Fixes #149010
12 days[clang-format] Add IgnoreExtension to SortIncludes (#137840)Daan De Meyer2-9/+33
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] Add MacrosSkippedByRemoveParentheses option (#148345)Owen Pan2-0/+5
This allows RemoveParentheses to skip the invocations of function-like macros. Fixes #68354. Fixes #147780.
2025-07-10[clang-format] Split line comments separated by backslashes (#147648)Owen Pan2-10/+15
Fixes #147341
2025-07-05[clang-format] Propagate `LeadingEmptyLinesAffected` when joining lines ↵Eric Li1-0/+5
(#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-14/+0
2025-06-28[clang-format] Fix a bug in `ReflowComments: Always` (#146202)Owen Pan1-1/+1
Fixes #39150
2025-06-26[clang-format][NFC] Remove `\brief` from comments (#145853)Owen Pan1-1/+1
This was done before in https://reviews.llvm.org/D46320
2025-06-25[clang-format] Handle Trailing Whitespace After Line Continuation (P2223R2) ↵Naveen Seth Hanig1-0/+15
(#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-25[clang-format] Improve QualifierAlignment in guessing macros (#145468)Owen Pan1-2/+5
Fixes #145388
2025-06-14[clang-format] Fix a bug in annotating braces (#144095)Owen Pan1-0/+7
Stop looking for function decls after hitting a BK_BracedInit brace. Fixes #144057.
2025-06-09[clang-format] Parse JSON outermost l_brace as braced list brace (#143327)Owen Pan2-0/+16
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-0/+5
2025-06-05[clang-format] Handle requires clause following a pointer type (#142893)Owen Pan1-0/+9
Fix #142818
2025-06-02[clang-format] Correctly annotate token-pasted function decl names (#142337)Owen Pan1-0/+7
Fix #142178
2025-06-01Revert "[clang-format] Handle token-pasted function decl names (#142251)"Owen Pan1-7/+0
This reverts commit 29f79ea3c59649f7686a09845665660c25ca3f9b which caused a regression. See https://github.com/llvm/llvm-project/pull/142251#issuecomment-2928718530.
2025-05-31[clang-format] Handle token-pasted function decl names (#142251)Owen Pan1-0/+7
Fix #142178
2025-05-30[clang-format] Handle bit-field colon of non-numeric-constant size (#142110)Owen Pan1-0/+8
Fix #142050
2025-05-28[clang-format] Handle .h files for LK_C and LK_ObjC (#141714)Owen Pan1-0/+18
Fix #137792
2025-05-25[clang-format] Handle Java text blocks (#141334)Owen Pan1-0/+57
Fix #61954
2025-05-20[clang-format] Handle raw string literals containing JSON code (#140666)Owen Pan1-0/+22
Fix #65400
2025-05-19[clang-format][NFC] Upgrade SortIncludes option to a struct (#140497)Owen Pan4-12/+17
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-0/+7
Fix #62356
2025-05-19[clang-format] Fix the indent of StartOfName after AttributeMacro (#140361)Owen Pan1-0/+7
Fix #139510
2025-05-09[clang-format] Handle Java record (#139215)Owen Pan1-0/+11
Fix #62089
2025-05-08[clang-format] Handle C# where clause in SeparateDefinitionBlocks (#139034)Owen Pan1-0/+5
Fix #61956
2025-05-07[clang-format] Add SpaceAfterOperatorKeyword option (#137610)Filip Milosevic2-0/+7
Add SpaceAfterOperatorKeyword option to clang-format
2025-05-07[clang-format] Correctly annotate ObjC `* __autoreleasing *` (#138799)Owen Pan1-0/+6
Fix #138484
2025-05-06[clang-format] Fix a bug in annotating binary operator && (#138633)Owen Pan1-0/+7
Fix #138485
2025-05-06[clang-format] Correctly annotate C# nullable value type `?` (#138631)Owen Pan1-0/+13
Fix #78666
2025-05-06[clang-format] Don't annotate enum colon as InheritanceColon (#138440)Owen Pan1-0/+6
Fix #61156
2025-05-03[clang-format] Correctly annotate tok::star in braced list (#138389)Owen Pan1-0/+5
Fix #138382
2025-05-02[clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)Owen Pan1-0/+2
Fix #138097
2025-05-02[clang-format] RemoveParentheses shouldn't remove empty parentheses (#138229)Owen Pan1-0/+2
Fix #138124
2025-04-30[clang-format] Correctly annotate user-defined conversion function call ↵Owen Pan1-2/+8
(#137914) Fix #137770
2025-04-30Reland [clang-format] Add OneLineFormatOffRegex option (#137577)Owen Pan2-0/+100
2025-04-30[clang] Shard out some small gtest binaries (#138021)Reid Kleckner1-1/+3
@nico mentioned that FormatTests and BasicTests are small binaries with few dependencies, so keeping them separate is nice. I broke them out as distinct test binaries, and they are still pretty small: $ find tools/clang/unittests/ -type f -name '*Tests' | xargs du -cksh | sort -nr 708M total 276M tools/clang/unittests/AllClangUnitTests 244M tools/clang/unittests/Interpreter/ClangReplInterpreterTests 167M tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests 13M tools/clang/unittests/Format/FormatTests 6.9M tools/clang/unittests/Basic/BasicTests 1.1M tools/clang/unittests/libclang/CrashTests/libclangCrashTests I also broke out libclangCrashTests and re-enabled the failing test to resolve llvm#137855.
2025-04-30Revert "[clang-format] Add OneLineFormatOffRegex option (#137577)"Owen Pan2-100/+0
This reverts commit b8bb1ccb4f9126d1bc9817be24e17f186a75a08b which triggered an assertion failure in CodeGenTest.TestNonAlterTest.
2025-04-29[clang-format] Add OneLineFormatOffRegex option (#137577)Owen Pan2-0/+100
Close #54334
2025-04-26[clang-format] Annotate tok::star in a*b*c as BinaryOperator (#137433)Owen Pan1-0/+5
Fix #137400
2025-04-26[clang-format] Correctly handle C# new modifier (#137430)Owen Pan2-0/+18
Fix #75815