This revision was automatically updated to reflect the committed changes. Closed by commit rC353033: [clang-format] Fix breaking of qualified operator (authored by krasimir, committed by ). Herald added a subscriber: cfe-commits.
Changed prior to commit: https://reviews.llvm.org/D57604?vs=184791&id=185009#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D57604/new/ https://reviews.llvm.org/D57604 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTest.cpp Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2249,6 +2249,9 @@ return 500; } + if (Left.is(tok::coloncolon) || + (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto)) + return 500; if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) || Right.is(tok::kw_operator)) { if (Line.startsWith(tok::kw_for) && Right.PartOfMultiVariableDeclStmt) @@ -2267,9 +2270,6 @@ return 160; if (Left.is(TT_CastRParen)) return 100; - if (Left.is(tok::coloncolon) || - (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto)) - return 500; if (Left.isOneOf(tok::kw_class, tok::kw_struct)) return 5000; if (Left.is(tok::comment)) Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -4183,6 +4183,18 @@ Style); } +TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) { + // Regression test for https://bugs.llvm.org/show_bug.cgi?id=40516: + // Prefer keeping `::` followed by `operator` together. + EXPECT_EQ("const aaaa::bbbbbbb &\n" + "ccccccccc::operator++() {\n" + " stuff();\n" + "}", + format("const aaaa::bbbbbbb\n" + "&ccccccccc::operator++() { stuff(); }", + getLLVMStyleWithColumns(40))); +} + TEST_F(FormatTest, TrailingReturnType) { verifyFormat("auto foo() -> int;\n"); verifyFormat("struct S {\n"
Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2249,6 +2249,9 @@ return 500; } + if (Left.is(tok::coloncolon) || + (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto)) + return 500; if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) || Right.is(tok::kw_operator)) { if (Line.startsWith(tok::kw_for) && Right.PartOfMultiVariableDeclStmt) @@ -2267,9 +2270,6 @@ return 160; if (Left.is(TT_CastRParen)) return 100; - if (Left.is(tok::coloncolon) || - (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto)) - return 500; if (Left.isOneOf(tok::kw_class, tok::kw_struct)) return 5000; if (Left.is(tok::comment)) Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -4183,6 +4183,18 @@ Style); } +TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) { + // Regression test for https://bugs.llvm.org/show_bug.cgi?id=40516: + // Prefer keeping `::` followed by `operator` together. + EXPECT_EQ("const aaaa::bbbbbbb &\n" + "ccccccccc::operator++() {\n" + " stuff();\n" + "}", + format("const aaaa::bbbbbbb\n" + "&ccccccccc::operator++() { stuff(); }", + getLLVMStyleWithColumns(40))); +} + TEST_F(FormatTest, TrailingReturnType) { verifyFormat("auto foo() -> int;\n"); verifyFormat("struct S {\n"
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits