This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
curdeius marked 2 inline comments as done.
Closed by commit rGca0d97072e79: [clang-format] Avoid merging macro
definitions. (authored by curdeius).
Changed prior to commit:
https://reviews.llvm.org/D118879?vs=405539&id=405693#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118879/new/
https://reviews.llvm.org/D118879
Files:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ 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) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -621,6 +621,10 @@
tryMergeSimpleBlock(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
SmallVectorImpl<AnnotatedLine *>::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.
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ 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) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -621,6 +621,10 @@
tryMergeSimpleBlock(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
SmallVectorImpl<AnnotatedLine *>::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.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits