aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/QualifierAlignmentFixer.cpp
diff options
context:
space:
mode:
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-02-21 14:17:58 +0100
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-02-24 10:16:10 +0100
commit46f6c834d9f95d99e0a85aa0c6dc07419aa6dee2 (patch)
tree7044a67226feed8dba9f2b8c5aa3dd12c0bb0fb1 /clang/lib/Format/QualifierAlignmentFixer.cpp
parentff3f3a54e2d1b05c36943bf88ae0be7475d622ed (diff)
downloadllvm-46f6c834d9f95d99e0a85aa0c6dc07419aa6dee2.zip
llvm-46f6c834d9f95d99e0a85aa0c6dc07419aa6dee2.tar.gz
llvm-46f6c834d9f95d99e0a85aa0c6dc07419aa6dee2.tar.bz2
[clang-format] Fix QualifierOrder breaking the code with requires clause.
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
Diffstat (limited to 'clang/lib/Format/QualifierAlignmentFixer.cpp')
-rw-r--r--clang/lib/Format/QualifierAlignmentFixer.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 233b081..aff5562 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -328,14 +328,17 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
if (Next->is(tok::comment) && Next->getNextNonComment())
Next = Next->getNextNonComment();
assert(Next->MatchingParen && "Missing template closer");
- Next = Next->MatchingParen->Next;
+ Next = Next->MatchingParen;
+ if (Next->ClosesRequiresClause)
+ return Next;
+ Next = Next->Next;
// Move to the end of any template class members e.g.
// `Foo<int>::iterator`.
if (Next && Next->startsSequence(tok::coloncolon, tok::identifier))
Next = Next->Next->Next;
if (Next && Next->is(QualifierType)) {
- // Remove the const.
+ // Move the qualifier.
insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
removeToken(SourceMgr, Fixes, Next);
return Next;
@@ -344,7 +347,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
if (Next && Next->Next &&
Next->Next->isOneOf(tok::amp, tok::ampamp, tok::star)) {
if (Next->is(QualifierType)) {
- // Remove the qualifier.
+ // Move the qualifier.
insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
removeToken(SourceMgr, Fixes, Next);
return Next;