Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -460,8 +460,8 @@ /// /// \param Standard determines lexing mode: LC_Cpp11 and LS_Auto turn on C++11 /// lexing mode, LS_Cpp03 - C++03 mode. -LangOptions getFormattingLangOpts(FormatStyle::LanguageStandard Standard = - FormatStyle::LS_Cpp11); +LangOptions getFormattingLangOpts( + FormatStyle::LanguageStandard Standard = FormatStyle::LS_Cpp11); /// \brief Description to be used for help text for a llvm::cl option for /// specifying format style. The description is closely related to the operation Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -1852,6 +1852,7 @@ LangOpts.CPlusPlus11 = Standard == FormatStyle::LS_Cpp03 ? 0 : 1; LangOpts.CPlusPlus1y = Standard == FormatStyle::LS_Cpp03 ? 0 : 1; LangOpts.LineComment = 1; + LangOpts.CXXOperatorNames = 1; LangOpts.Bool = 1; LangOpts.ObjC1 = 1; LangOpts.ObjC2 = 1; Index: tools/clang-format/ClangFormat.cpp =================================================================== --- tools/clang-format/ClangFormat.cpp +++ tools/clang-format/ClangFormat.cpp @@ -246,8 +246,8 @@ return true; } else { if (Cursor.getNumOccurrences() != 0) - outs() << "{ \"Cursor\": " << tooling::shiftedCodePosition( - Replaces, Cursor) << " }\n"; + outs() << "{ \"Cursor\": " + << tooling::shiftedCodePosition(Replaces, Cursor) << " }\n"; Rewrite.getEditBuffer(ID).write(outs()); } } Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -270,6 +270,17 @@ 9, 5, getLLVMStyle())); } +TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) { + verifyFormat("x = (a) and (b);"); + verifyFormat("x = (a) or (b);"); + verifyFormat("x = (a) bitand (b);"); + verifyFormat("x = (a) bitor (b);"); + verifyFormat("x = (a) not_eq (b);"); + verifyFormat("x = (a) and_eq (b);"); + verifyFormat("x = (a) or_eq (b);"); + verifyFormat("x = (a) xor (b);"); +} + //===----------------------------------------------------------------------===// // Tests for control statements. //===----------------------------------------------------------------------===// @@ -2844,9 +2855,21 @@ "bool aaaaaaa =\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaa).aaaaaaaaaaaaaaaaaaa() ||\n" " bbbbbbbb();"); + verifyFormat( + "bool aaaaaaa =\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaa).aaaaaaaaaaaaaaaaaaa() or\n" + " bbbbbbbb();"); + verifyFormat("bool aaaaaaaaaaaaaaaaaaaaa =\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbb &&\n" " ccccccccc == ddddddddddd;"); + verifyFormat("bool aaaaaaaaaaaaaaaaaaaaa =\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbb and\n" + " ccccccccc == ddddddddddd;"); + verifyFormat( + "bool aaaaaaaaaaaaaaaaaaaaa =\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa not_eq bbbbbbbbbbbbbbbbbb and\n" + " ccccccccc == ddddddddddd;"); verifyFormat("aaaaaa = aaaaaaa(aaaaaaa, // break\n" " aaaaaa) &&\n" @@ -3592,20 +3615,42 @@ verifyFormat( "if (aaaaaaaaaaaaaaaaaaaaaaaaa ||\n" " bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) {\n}"); + verifyFormat( + "if (aaaaaaaaaaaaaaaaaaaaaaaaa or\n" + " bbbbbbbbbbbbbbbbbbbbbbbbb and cccccccccccccccccccccccc) {\n}"); + verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaa && bbbbbbbbbbbbbbbbbbbbbbbbb ||\n" " ccccccccccccccccccccccccc) {\n}"); + verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaa and bbbbbbbbbbbbbbbbbbbbbbbb or\n" + " ccccccccccccccccccccccccc) {\n}"); + verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb ||\n" " ccccccccccccccccccccccccc) {\n}"); + verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaa or bbbbbbbbbbbbbbbbbbbbbbbbb or\n" + " ccccccccccccccccccccccccc) {\n}"); + verifyFormat( "if ((aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb) &&\n" " ccccccccccccccccccccccccc) {\n}"); + verifyFormat( + "if ((aaaaaaaaaaaaaaaaaaaaaaaaa or bbbbbbbbbbbbbbbbbbbbbbbbb) and\n" + " ccccccccccccccccccccccccc) {\n}"); + verifyFormat("return aaaa & AAAAAAAAAAAAAAAAAAAAAAAAAAAAA ||\n" " bbbb & BBBBBBBBBBBBBBBBBBBBBBBBBBBBB ||\n" " cccc & CCCCCCCCCCCCCCCCCCCCCCCCCC ||\n" " dddd & DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD;"); + verifyFormat("return aaaa & AAAAAAAAAAAAAAAAAAAAAAAAAAAAA or\n" + " bbbb & BBBBBBBBBBBBBBBBBBBBBBBBBBBBB or\n" + " cccc & CCCCCCCCCCCCCCCCCCCCCCCCCC or\n" + " dddd & DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD;"); + verifyFormat("if ((aaaaaaaaaa != aaaaaaaaaaaaaaa ||\n" " aaaaaaaaaaaaaaaaaaaaaaaa() >= aaaaaaaaaaaaaaaaaaaa) &&\n" " aaaaaaaaaaaaaaa != aa) {\n}"); + verifyFormat("if ((aaaaaaaaaa != aaaaaaaaaaaaaaa or\n" + " aaaaaaaaaaaaaaaaaaaaaaaa() >= aaaaaaaaaaaaaaaaaaaa) and\n" + " aaaaaaaaaaaaaaa != aa) {\n}"); } TEST_F(FormatTest, BreaksAfterAssignments) { Index: unittests/Format/FormatTestProto.cpp =================================================================== --- unittests/Format/FormatTestProto.cpp +++ unittests/Format/FormatTestProto.cpp @@ -52,10 +52,10 @@ "}"); verifyFormat("message SomeMessage {\n" - " optional really.really.long.and.qualified.type.aaaaaaa\n" + " optional really.really.long.qualified.type.aaa.aaaaaaa\n" " fiiiiiiiiiiiiiiiiiiiiiiiiield = 1;\n" " optional\n" - " really.really.long.and.qualified.type.aaaaaaa.aaaaaaaa\n" + " really.really.long.qualified.type.aaa.aaaaaaa.aaaaaaaa\n" " another_fiiiiiiiiiiiiiiiiiiiiield = 2;\n" "}"); }