[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 12:46:55 PST 2022
glotchimo updated this revision to Diff 400623.
glotchimo marked 4 inline comments as done.
glotchimo added a comment.
Use `getPreviousNonComment` to account for inline comments.
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,34 @@
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);
+ verifyFormat("/* long long padding */ 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,17 @@
if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
return false;
+ // Do not align operator= overloads.
+ FormatToken *Previous = C.Tok->getPreviousNonComment();
+ if (Previous && 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.400623.patch
Type: text/x-patch
Size: 2427 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220117/f0208d3c/attachment.bin>
More information about the cfe-commits
mailing list