glotchimo created this revision. glotchimo added a comment. glotchimo updated this revision to Diff 400390. glotchimo added reviewers: MyDeveloperDay, djasper. glotchimo added a project: clang-format. glotchimo added a subscriber: cfe-commits. glotchimo published this revision for review. Herald added a project: clang.
I don't know why, but `clang-format` reformatted most if not all of the long/block comments in `WhitespaceManager.cpp`. Will it be necessary for me to revert the changes to those comments and skip formatting when updating the diff so as to keep it minimal? glotchimo added a comment. Same change as before but without the changes to long and block comments. Added a look-ahead for brackets in the operator= context to avoid incorrect alignment. Repository: rG LLVM Github Monorepo 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,14 @@ 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); // 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)) { + auto *Next = C.Tok->Next; + while (Next && Next->NewlinesBefore == 0) { + if (Next->Tok.is(tok::l_brace)) + return false; + Next = Next->Next; + } + } + return C.Tok->is(tok::equal); }, Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments);
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -16167,6 +16167,14 @@ 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); // 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)) { + auto *Next = C.Tok->Next; + while (Next && Next->NewlinesBefore == 0) { + if (Next->Tok.is(tok::l_brace)) + return false; + Next = Next->Next; + } + } + return C.Tok->is(tok::equal); }, Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits