summaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestComments.cpp
AgeCommit message (Collapse)Author
2025-11-07[clang-format] Add option to separate comment alignment between ... (#165033)Björn Schäpers
normal lines and PP directives. Handling PP directives differently can be desired, like in #161848. Changing the default is not an option, there are tests for exactly the current behaviour.
2025-11-02[clang-format][NFC] Clean up FormatTestComments.cpp (#166029)owenca
- Replace verifyFormat(Foo, Bar, ...) with verifyFormat(Foo, ...) or verifyNoChange(Foo, ...) if Foo = Bar. - Other minor cleanups
2025-10-29[clang-format][NFC] Port FormatTestComments to verifyFormat (#164310)Björn Schäpers
And reduce the number of getLLVMStyleWithColumnLimit calls.
2025-10-21[clang-format] Fix repeated backslash insertion in macro line comments (#164300)Ruoyu Zhong
Line comments in preprocessor directives were incorrectly marked as continuing the directive, causing clang-format to add backslashes after them on repeated runs. Backslashes appended after line comments in this way do not continue the PP directive because the following line would also become part of the comment. Fix by unsetting `InPPDirective` in `WhitespaceManager::replaceWhitespace` for line comments in two places: when breaking lines and when formatting tokens on the same line. This stops the spurious backslash insertion for both standalone line comments after PP directives and trailing line comments after macro bodies. Fixes https://github.com/llvm/llvm-project/issues/164282. Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
2025-10-18[clang-format] Remove special handling of comments after brace/paren (#71672)Björn Schäpers
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-07-21[clang-format][NFC] Clean up around StringRef initializations (#149765)Owen Pan
Consistently use `constexpr StringRef Code("string literal");`.
2025-07-10[clang-format] Split line comments separated by backslashes (#147648)Owen Pan
Fixes #147341
2025-06-28[clang-format] Fix a bug in `ReflowComments: Always` (#146202)Owen Pan
Fixes #39150
2024-10-11[clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments ↵Iuri Chaer
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-08-22[clang-format] Change BinPackParameters to enum and add AlwaysOnePerLine ↵Tom
(#101882) Related issues that have requested this feature: #51833 #23796 #53190 Partially solves - this issue requests is for both arguments and parameters
2024-07-11[clang-format] Fix a bug in TCAS_Leave using tabs for indentation (#98427)Owen Pan
Fixes #92530.
2024-06-14[clang-format] Don't over-indent comment below unbraced body (#95354)Owen Pan
Fixes #45002.
2024-04-12[clang-format] Fix a regression in ContinuationIndenter (#88414)Owen Pan
Commit d06b92391513 caused a regression that breaks after a block comment adjacent to a function paramter that follows. Fixes #86573.
2024-02-06[clang-format] Handle doxygen commands starting with \ (#80381)Fernando Tagawa
Fixes llvm/llvm-project#63241 Doxygen commands can start with `@` or `\`.
2023-12-06[clang-format] Handle merging functions containing only a block comment (#74651)Owen Pan
Fixed #41854.
2023-11-19[clang-format] Fix a bug in aligning comments above PPDirective (#72791)Owen Pan
Fixed #72785.
2023-10-26[clang-format][NFC] Remove extraneous newlines in some unit test filesOwen Pan
2023-10-25[clang-format] Don't align comments over scopesBjörn Schäpers
We now stop aligning trailing comments on all closing braces, for classes etc. we even check for the semicolon between the comment and the brace. Fixes #67906.
2023-09-24[clang-format] Fix a bug in aligning trailing comments (#67221)Owen Pan
Fixes #67116.
2023-08-02[clang-format] Supress aligning of trailing namespace commentsBjörn Schäpers
Fixes https://github.com/llvm/llvm-project/issues/57504. Differential Revision: https://reviews.llvm.org/D138263
2023-07-24[clang-format] Insert namespace comments with leading spacesOwen Pan
Insert missing namespace comments with SpacesBeforeTrailingComments leading spaces. Fixes #64051. Differential Revision: https://reviews.llvm.org/D156065
2023-07-12[clang-format] Correctly count a tab's width in a commentBjörn Schäpers
It worked only correct for a tab as the first char. Fixes https://github.com/llvm/llvm-project/issues/56769 Differential Revision: https://reviews.llvm.org/D138402
2023-06-17[clang-format][NFC] Remove redundant getLLVMStyle() in unit testsOwen Pan
2023-06-16[clang-format][NFC] Clean up unit testsOwen Pan
This patch adds a verifyNoChange macro to verify code that won't change after being formatted. (The code will not be messed up before being formatted.) It then replaces EXPECT_EQ with verifyFormat wherever applicable so that the code will be messed up before being formatted. When the replacement fails the unit test, verifyFormat is replaced with verifyNoChange. Differential Revision: https://reviews.llvm.org/D153109
2023-05-09[clang-format] Put a "trailing" space back in a unit testOwen Pan
Put an intentional "trailing" space back in FormatTestComments.SplitCommentIntroducers. It was removed in a4c87f8ccacc by mistake.
2023-05-08[clang-format] Fix consecutive alignments in #else blocksOwen Pan
Since 3.8 or earlier, clang-format has been lumping all #else, #elif, etc blocks together when doing whitespace replacements and causing consecutive alignments across #else blocks. Commit c077975 partially addressed the problem but also triggered "regressions". This patch fixes the root cause of the problem and "reverts" c077975 (except for the unit tests). Fixes #36070. Fixes #55265. Fixes #60721. Fixes #61498. Differential Revision: https://reviews.llvm.org/D150057
2023-04-14[clang-format] Correctly indent comment above finalized PPDirectiveOwen Pan
Fixes #62107. Differential Revision: https://reviews.llvm.org/D148200
2023-03-01[clang-format][NFC] Refactor formatting unit tests.Manuel Klimek
Pull out common base class for formatting unit tests, removing duplicate code that accumulated over the years. Pull out macro expansion test into its own test file.
2022-12-01[clang-format] Don't move comments if AlignTrailingComments: LeaveMaíra Canal
For comments that start after a new line, currently, the comments are being indented. This happens because the OriginalWhitespaceRange considers newlines on the range. Therefore, when AlignTrailingComments: Kind: Leave, deduct the number of newlines before the token to calculate the number of spaces for trailing comments. Fixes #59203. Differential Revision: https://reviews.llvm.org/D139029
2022-11-21[clang-format][NFC] Removed unused includeBjörn Schäpers
2022-10-30[clang-format] Adds a formatter for aligning trailing comments over empty linesYusuke Kadowaki
This patch addresses https://github.com/llvm/llvm-project/issues/19756 Reviewed By: MyDeveloperDay, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D132131
2022-03-13[clang-format] Add space to comments starting with '#'.Marek Kurdej
Fixes https://github.com/llvm/llvm-project/issues/35116. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D121451
2022-02-20Fix extraneous whitespace addition in line comments on clang-format directivesLuis Penagos
Fixes https://github.com/llvm/llvm-project/issues/53844. I believe this regression was caused by not accounting for clang-format directives in https://reviews.llvm.org/D92257. Reviewed By: HazardyKnusperkeks, curdeius Differential Revision: https://reviews.llvm.org/D120188
2022-02-16[clang-format] Add test for SpacesInLineCommentPrefix. NFC.Marek Kurdej
Fixes https://github.com/llvm/llvm-project/issues/52649. This was already fixed in commit https://github.com/llvm/llvm-project/commit/e967d97a35a93c883528a9672159edff05f5addb.
2022-02-14[clang-format] Fix SpacesInLineCommentPrefix deleting tokens.Marek Kurdej
Fixes https://github.com/llvm/llvm-project/issues/53799. Reviewed By: HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D119680
2022-02-13Avoid a vulgarism. NFC.Marek Kurdej
2022-02-03[clang-format] Use wider comment prefix space ruleksyx
This commit changes the condition of requiring comment to start with alphanumeric characters to make no change only for a certain set of characters, currently horizontal whitespace and punctuation characters, to support wider set of leading characters unrelated to documentation generation directives. Reviewed By: HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D118869
2022-01-28[clang-format] Fix misaligned trailing comments in the presence of an empty ↵Marek Kurdej
block comment. Fixes https://github.com/llvm/llvm-project/issues/53441. Expected code: ``` /**/ // int a; // ``` was before misformatted to: ``` /**/ // int a; // ``` Because the "remaining length" (after the starting `/*`) of an empty block comment `/**/` was computed to be 0 instead of 2. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D118475
2021-12-01Fix a violated precondition in clang-format.Manuel Klimek
Make sure we do not try to change line comments that are non-regular, i.e. do not start with "//" or "#". This can for example happen when "//" is broken into two lines with an escaped newline.
2021-03-01[clang-format] Respect spaces in line comment section...Björn Schäpers
... without an active column limit. Before line comments were not touched at all with ColumnLimit == 0. Differential Revision: https://reviews.llvm.org/D96896
2021-02-01[clang-format] Add option to control the spaces in a line commentBjörn Schäpers
Differential Revision: https://reviews.llvm.org/D92257
2021-01-29Revert "[clang-format] Add option to control the spaces in a line comment"Björn Schäpers
This reverts commit 078f30e04d1fcb5a05d8e340f3178f3478075541.
2021-01-29[clang-format] Add option to control the spaces in a line commentBjörn Schäpers
Differential Revision: https://reviews.llvm.org/D92257
2020-12-23[clang-format] PR48539 ReflowComments breaks Qt translation commentsmydeveloperday
https://bugs.llvm.org/show_bug.cgi?id=48539 Add support for Qt Translator Comments to reflow When reflown and a part of the comments are added on a new line, it should repeat these extra characters as part of the comment token. Reviewed By: curdeius, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D93490
2020-11-09[clang-format] avoid introducing multiline commentsKrasimir Georgiev
In C++ with -Werror=comment, multiline comments are not allowed. clang-format could accidentally introduce multiline comments when reflowing. This adapts clang-format to not introduce multiline comments by not allowing a break after `\`. Note that this does not apply to comment lines that already are multiline comments, such as comments in macros. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D90949
2020-10-20[clang-format] Drop clangFrontend dependency for FormatTestsAlex Richardson
This allows building the clang-format unit tests in only 657 ninja steps rather than 1257 which allows for much faster incremental builds after a git pull. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D89709
2020-10-17Revert "[clang-format] Fix AlignConsecutive on PP blocks"Sylvestre Ledru
This reverts commit b2eb439317576ce718193763c12bff9fccdfc166. Caused the regression: https://bugs.llvm.org/show_bug.cgi?id=47589 Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D89464
2020-05-13[clang-format] Fix AlignConsecutive on PP blocksmydeveloperday
Summary: Currently the 'AlignConsecutive*' options incorrectly align across elif and else statements, even if they are very far away and across unrelated preprocessor macros. This failed since on preprocessor run 2+, there is not enough context about the #ifdefs to actually differentiate one block from another, causing them to align across different blocks or even large sections of the file. Eg, with AlignConsecutiveAssignments: ``` \#if FOO // Run 1 \#else // Run 1 int a = 1; // Run 2, wrong \#endif // Run 1 \#if FOO // Run 1 \#else // Run 1 int bar = 1; // Run 2 \#endif // Run 1 ``` is read as ``` int a = 1; // Run 2, wrong int bar = 1; // Run 2 ``` The approach taken to fix this was to add a new flag to Token that forces breaking alignment across groups of lines (MustBreakAlignBefore) in a similar manner to the existing flag that forces a line break (MustBreakBefore). This flag is set for the first Token after a preprocessor statement or diff conflict marker. Fixes #25167,#31281 Patch By: JakeMerdichAMD Reviewed By: MyDeveloperDay Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D79388
2020-05-02[clang-format] NFC - clang-format the FormatTestsmydeveloperday
Summary: Ensure the clang-format unit tests are themselves clang-formatted Having areas of the llvm code which are clang-format clean, give us more areas to run new clang-format binaries on ensuring we haven't broken anything. It seems to me we SHOULD have this clang-formatted at a minimum, otherwise how can we expect others to use clang-format if we "don't eat our own dogfood", also if the tests are dependent on the formatting of the code then that would also be bad! Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D79204
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636