[PATCH] D117421: [clang-format] Fix incorrect alignment of operator= overloads.
Elliott Maguire via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 17 10:30:30 PST 2022
glotchimo updated this revision to Diff 400606.
glotchimo marked an inline comment as done.
glotchimo added a comment.
Add overload declaration look-ahead.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117421/new/
https://reviews.llvm.org/D117421
Files:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16167,6 +16167,30 @@
verifyFormat("int oneTwoThree = 123; // comment\n"
"int oneTwo = 12; // comment",
Alignment);
+ verifyFormat("int() = default;\n"
+ "int &operator() = default;\n"
+ "int &operator=() {",
+ Alignment);
+ verifyFormat("int() = default; // comment\n"
+ "int &operator() = default; // comment\n"
+ "int &operator=() {",
+ Alignment);
+ verifyFormat("int() = default;\n"
+ "int &operator() = default;\n"
+ "int &operator==() {",
+ Alignment);
+ verifyFormat("int() = default;\n"
+ "int &operator() = default;\n"
+ "int &operator<=() {",
+ Alignment);
+ verifyFormat("int() = default;\n"
+ "int &operator() = default;\n"
+ "int &operator!=() {",
+ Alignment);
+ verifyFormat("int() = default;\n"
+ "int &operator() = default;\n"
+ "int &operator=();",
+ Alignment);
// Bug 25167
/* Uncomment when fixed
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -731,6 +731,16 @@
if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
return false;
+ // Do not align operator= overloads.
+ if (C.Tok->Previous && C.Tok->Previous->is(tok::kw_operator)) {
+ FormatToken *Next = C.Tok->Next;
+ while (Next && Next->NewlinesBefore == 0) {
+ if (Next->Tok.isOneOf(tok::l_brace, tok::semi))
+ return false;
+ Next = Next->Next;
+ }
+ }
+
return C.Tok->is(tok::equal);
},
Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117421.400606.patch
Type: text/x-patch
Size: 2184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220117/079ebc51/attachment.bin>
More information about the cfe-commits
mailing list