diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -621,6 +621,10 @@ tryMergeSimpleBlock(SmallVectorImpl::const_iterator I, SmallVectorImpl::const_iterator E, unsigned Limit) { + // Don't merge with a preprocessor directive. + if (I[1]->Type == LT_PreprocessorDirective) + return 0; + AnnotatedLine &Line = **I; // Don't merge ObjC @ keywords and methods. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1805,6 +1805,21 @@ verifyFormat("#define xor(x) (^(x))"); verifyFormat("#define __except(x)"); verifyFormat("#define __try(x)"); + + FormatStyle Style = getLLVMStyle(); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterFunction = true; + // Test that a macro definition never gets merged with the following + // definition. + // FIXME: The AAA macro definition probably should not be split into 3 lines. + verifyFormat("#define AAA " + " \\\n" + " N " + " \\\n" + " {\n" + "#define BBB }\n", + Style); + // verifyFormat("#define AAA N { //\n", Style); } TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {