[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 19:34:34 PST 2022
glotchimo updated this revision to Diff 400696.
glotchimo marked an inline comment as done.
glotchimo added a comment.
Simplify by removing look-ahead (unnecessary b/c of difference between ident and tokens).
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,11 @@
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))
+ return false;
+
return C.Tok->is(tok::equal);
},
Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117421.400696.patch
Type: text/x-patch
Size: 2205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220118/f03374b6/attachment-0001.bin>
More information about the cfe-commits
mailing list