[PATCH] D120309: [clang-format] Fix QualifierOrder breaking the code with requires clause.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 24 01:16:18 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG46f6c834d9f9: [clang-format] Fix QualifierOrder breaking the code with requires clause. (authored by curdeius).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120309/new/
https://reviews.llvm.org/D120309
Files:
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp
Index: clang/unittests/Format/QualifierFixerTest.cpp
===================================================================
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -858,6 +858,21 @@
Style);
}
+TEST_F(QualifierFixerTest, WithConstraints) {
+ FormatStyle Style = getLLVMStyle();
+ Style.QualifierAlignment = FormatStyle::QAS_Custom;
+ Style.QualifierOrder = {"constexpr", "type"};
+
+ verifyFormat("template <typename T>\n"
+ " requires Concept<F>\n"
+ "constexpr constructor();",
+ Style);
+ verifyFormat("template <typename T>\n"
+ " requires Concept1<F> && Concept2<F>\n"
+ "constexpr constructor();",
+ Style);
+}
+
TEST_F(QualifierFixerTest, DisableRegions) {
FormatStyle Style = getLLVMStyle();
Style.QualifierAlignment = FormatStyle::QAS_Custom;
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===================================================================
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -328,14 +328,17 @@
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 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120309.411033.patch
Type: text/x-patch
Size: 2304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220224/9cc8944e/attachment.bin>
More information about the cfe-commits
mailing list