summaryrefslogtreecommitdiff
path: root/clang/lib/Format/QualifierAlignmentFixer.cpp
AgeCommit message (Collapse)Author
2025-11-12[clang-format] Don't swap `(const override)` with QAS_Right (#167191)owenca
Fixes #154846
2025-10-02[clang-format][NFC] Introduce isNoneOf (#161021)Björn Schäpers
And apply throughout the code base.
2025-09-27[clang-format] Fix qualifier ordering for lines after PP directives (#160731)Ruoyu Zhong
Lines appearing after preprocessor conditional blocks (like `#endif`) were not having their qualifiers reordered by `QualifierOrder`, while lines inside the conditional blocks were processed correctly. The issue was that tokens on lines following preprocessor directives have `MustBreakBefore` = `true`. The qualifier alignment logic was breaking immediately upon encountering any token with `MustBreakBefore` = `true`, preventing analysis of the entire line. The fix allows processing to continue when `MustBreakBefore` = `true` on the first token of a line, since this is expected behavior (the token legitimately starts a new line). Only tokens with `MustBreakBefore` = `true` that appear mid-line will cause the analysis loop to break. Fixes https://github.com/llvm/llvm-project/issues/160487.
2025-07-06[clang-format][NFC] Replace size() with empty() (#147164)Owen Pan
2025-06-25[clang-format] Improve QualifierAlignment in guessing macros (#145468)Owen Pan
Fixes #145388
2025-05-31[Format] Remove unused includes (NFC) (#142296)Kazu Hirata
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-02-04[clang-format] Hanlde qualified type name for `QualifierAlignment` (#125327)Owen Pan
Fixes #125178.
2025-01-21[clang-format] Handle leading C++11 attribute in QualifierAlignment (#123690)Owen Pan
Fixes #123573.
2024-12-21[clang-format] Fix a crash in `QualifierAlignment: Right` (#120821)Owen Pan
Fixes #120793.
2024-05-13Reland "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"Owen Pan
Remove FormatToken::isSimpleTypeSpecifier() and call Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-05-13[clang-format][NFC] Move LeftRightQualifierAlignmentFixer::is...() (#91930)Owen Pan
Move static member functions LeftRightQualifierAlignmentFixer::is...() out of the class so that #91712 can reland.
2024-05-12Revert "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"Owen Pan
This reverts commits e62ce1f8842c, 5cd280433e8e, and de641e289269 due to buildbot failures.
2024-05-12Revert "[clang-format] Fix buildbot failures"Owen Pan
This reverts commit 0869204cff22831d0bb19a82c99bf85e4deb4ae3, which caused a buildbot failure: https://lab.llvm.org/buildbot/#/builders/5/builds/43322
2024-05-11[clang-format] Fix buildbot failuresOwen Pan
This effectively reverts 5cd280433e8e and changes to QualifierFixerTest.cpp from e62ce1f8842c. Failed buidbots: https://lab.llvm.org/buildbot/#/builders/236/builds/11223 https://lab.llvm.org/buildbot/#/builders/239/builds/6968
2024-05-10[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)Owen Pan
Remove FormatToken::isSimpleTypeSpecifier() and call Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-03-19Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"Owen Pan
This reverts commit b92d6dd704d789240685a336ad8b25a9f381b4cc. See github.com/llvm/llvm-project/commit/b92d6dd704d7#commitcomment-139992444 We should use a tool like Visual Studio to clean up the headers.
2024-03-19Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions ↵Owen Pan
(#84599)" This reverts c3a1eb6207d8 (and the related commit f3c5278efa3b) which makes cleanupAroundReplacements() no longer thread-safe.
2024-03-16[clang-format][NFC] Delete 100+ redundant #include lines in .cpp filesOwen Pan
2024-03-14Reland [clang-format][NFC] Eliminate the IsCpp parameter in all functions ↵Owen Pan
(#84599) Initialize IsCpp in LeftRightQualifierAlignmentFixer ctor.
2024-03-14Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions" ↵Mehdi Amini
(#85353) Reverts llvm/llvm-project#84599 This broke the presubmit bot.
2024-03-14[clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599)Owen Pan
2024-03-08[clang-format] Handle common C++ non-keyword types as such (#83709)Owen Pan
Fixes #83400.
2024-02-16[clang-format] Don't sort qualifiers across preprocessor directives (#81958)Owen Pan
Fixes #80579.
2023-11-16[clang-format] Handle lambdas in QualifierAlignment (#72456)Owen Pan
Fixed #62780.
2023-11-15[clang-format] Handle constrained auto in QualifierAlignment (#72251)Owen Pan
Fixed #69610.
2023-11-10[clang-format][NFC] Refactor isPointerOrReferenceOwen Pan
2023-08-30[clang-format][NFC] Reformat and fix file modeOwen Pan
Fix file mode errors introduced in 2c9372e78d7c and format errors in https://reviews.llvm.org/D155239.
2023-08-26[clang-format] Rename qualifier file comments (#64354)MyDeveloperDay
* [clang-format] rename the file comments to match the file name * [clang-format] rename the file comments to match the file name * Remove extraneous space * [clang-format] NFC remove EOF --------- Co-authored-by: paul_hoad <paul_hoad@amat.com>
2023-08-24[clang-format][NFC] Replace !is() with isNot()Owen Pan
Differential Revision: https://reviews.llvm.org/D158571
2023-07-11[clang-format][NFC] Remove redundant parentheses in the source codeOwen Pan
Reformat the source code with RemoveParentheses set to ReturnStatement.
2023-07-03[clang-format] Fixed bad performance with enabled qualifier fixer.Sedenion
This fixes github issue #57117: If the "QualifierAlignment" option of clang-format is set to anything else but "Leave", the "QualifierAlignmentFixer" pass gets enabled. This pass scales quadratically with the number of preprocessor branches, i.e. with the number of elements in TokenAnalyzer::UnwrappedLines. The reason is that QualifierAlignmentFixer::process() generates the UnwrappedLines, but then QualifierAlignmentFixer::analyze() calls LeftRightQualifierAlignmentFixer::process() several times (once for each qualifier) which again each time generates the UnwrappedLines. This commit gets rid of this double loop by registering the individual LeftRightQualifierAlignmentFixer passes directly in the top most container of passes (local variable "Passes" in reformat()). With this change, the original example in the github issue #57117 now takes only around 3s instead of >300s to format. Since QualifierAlignmentFixer::analyze() got deleted, we also no longer have the code with the NonNoOpFixes. This causes replacements that end up not changing anything to appear in the list of final replacements. There is a unit test to check that this does not happen: QualifierFixerTest.NoOpQualifierReplacements. However, it got broken at some point in time. So this commit fixes the test. To keep the behavior that no no-op replacements should appear from the qualifier fixer, the corresponding code from QualifierAlignmentFixer::analyze() was moved to the top reformat() function. Thus, is now done for **every** replacement of every formatting pass. If no-op replacements are a problem for the qualifier fixer, then it seems to be a good idea to filter them out always. See https://github.com/llvm/llvm-project/issues/57117#issuecomment-1546716934 for some more details. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D153228
2023-05-04[clang-format] Correctly limit formatted ranges when specifying qualifier ↵Colin Ogilvie
alignment The qualifier alignment fixer appeared to ignore any ranges specified for limiting formatting. This change ensures that it only formats affected lines to avoid unexpected changes. Fixes #54888. Differential Revision: https://reviews.llvm.org/D149643
2023-03-27[clang-format] Improve QualifierAlignmentAlexander Hederstaf
Qualifiers were not moved for non-pointer non-simple types. Add additional support for many special cases such as templates, requires clauses, long qualified names. Fixes https://github.com/llvm/llvm-project/issues/57154 and https://github.com/llvm/llvm-project/issues/60898 Reviewed By: MyDeveloperDay, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D144709
2023-02-25[clang-format] Don't move qualifiers past pointers-to-memberEmilia Dreamer
Previously, given a pointer-to-member type such as `Foo const Bar::*`, clang-format would see the `const Bar::` part as a regular type name with scope resolution operators, and with `QualifierAlignment: Right` it would attempt to "fix" it, resulting in `Foo Bar::const *`, a syntax error. This patch no longer allows qualifiers to be moved across `::*`. Fixes https://github.com/llvm/llvm-project/issues/60898 Reviewed By: owenpan, MyDeveloperDay, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D144537
2022-12-22[clang-format] Add 'friend' to QualifierOrderMicah Weston
For cases of defining friend functions, qualifier ordering can allow multiple positions for the 'friend' token. Closes #59450. Differential Revision: https://reviews.llvm.org/D139801
2022-12-09[Format] Use std::optional in QualifierAlignmentFixer.cpp (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-08-20Remove redundant initialization of Optional (NFC)Kazu Hirata
2022-05-26[clang-format] Fix QualifierAlignment with global namespace qualified types.Marek Kurdej
Fixes https://github.com/llvm/llvm-project/issues/55610. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D126096
2022-05-24[clang-format][NFC] Insert/remove braces in clang/lib/Format/owenca
Differential Revision: https://reviews.llvm.org/D126157
2022-04-01[clang-format] Fix a crash in qualifier alignmentOwen Pan
Related to #54513.
2022-03-28[clang-format] Don't format qualifiers in PPDirectiveowenca
Fixes #54513 Differential Revision: https://reviews.llvm.org/D122548
2022-03-05[clang-format] QualifierOrder does not reorder template argumentsmydeveloperday
https://github.com/llvm/llvm-project/issues/53981 Reorder the qualifiers inside the template argument. This should handle the simple cases of ``` <const T> <T const> ``` But only by relaxing that single letter capital variables are not possible macros Fixes: #53981 Reviewed By: HazardyKnusperkeks, curdeius Differential Revision: https://reviews.llvm.org/D120710
2022-02-24[clang-format] Fix QualifierOrder breaking the code with requires clause.Marek Kurdej
Fixes https://github.com/llvm/llvm-project/issues/53962. Given the config: ``` BasedOnStyle: LLVM QualifierAlignment: Custom QualifierOrder: ['constexpr', 'type'] ``` The code: ``` template <typename F> requires std::invocable<F> constexpr constructor(); ``` was incorrectly formatted to: ``` template <typename F> requires constexpr std::invocable<F> constructor(); ``` because we considered `std::invocable<F> constexpr` as a type, not recognising the requires clause. This patch avoids moving the qualifier across the boundary of the requires clause (checking `ClosesRequiresClause`). Reviewed By: HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D120309
2022-02-09[clang-format] Honour "// clang-format off" when using QualifierOrder.Marek Kurdej
Fixes https://github.com/llvm/llvm-project/issues/53643. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D119218
2022-02-08[clang-format] Comment unused parameters. NFC.Marek Kurdej
2022-02-08[clang-format] Fix typo. NFC.Marek Kurdej
2022-02-02[clang-format] Elide unnecessary braces. NFC.Marek Kurdej
2022-01-24[clang-format] Remove unused assignment. NFC.Marek Kurdej
Fixes scan-build reported warning: https://llvm.org/reports/scan-build/report-QualifierAlignmentFixer.cpp-analyzeRight-55-191910.html#EndPath.
2022-01-07[clang-format] Use range-for loops. NFC.Marek Kurdej
* Avoid if check on every element of the loop when printing symbols.
2022-01-06[clang-format] Fix a crash (assertion) in qualifier alignment when matching ↵mydeveloperday
template closer is null https://github.com/llvm/llvm-project/issues/53008 ``` template <class Id> using A = quantity /**/<kind<Id>, 1>; ``` the presence of the comment between identifier and template opener seems to be causing the qualifier alignment to fail Reviewed By: curdeius Fixes: #53008 Differential Revision: https://reviews.llvm.org/D116726