diff options
author | Nico Weber <nicolasweber@gmx.de> | 2014-11-13 16:25:37 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2014-11-13 16:25:37 +0000 |
commit | 34272657debfc462e0a1c4b77dd7a216309f72c2 (patch) | |
tree | 7b294e1c816bf85a4660102c0cc43275fc84ed23 /clang/unittests/Format/FormatTest.cpp | |
parent | 17072ef34813eb0a8f9dce4758167d78b504d1df (diff) | |
download | bcm5719-llvm-34272657debfc462e0a1c4b77dd7a216309f72c2.tar.gz bcm5719-llvm-34272657debfc462e0a1c4b77dd7a216309f72c2.zip |
clang-format: Format extern "C" blocks like namespace blocks.
namespace blocks act as if KeepEmptyLinesAtTheStartOfBlocks is always true,
and aren't collapsed to a single line even if they would fit. Do the same
for extern "C" blocks.
Before,
extern "C" {
void ExternCFunction();
}
was collapsed into `extern "C" { void ExternCFunction(); }`. Now it stays like
it was.
Fixes http://crbug.com/432640 and part of PR21419.
llvm-svn: 221897
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 37c3c0e7528..b8ab1df139b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -187,7 +187,7 @@ TEST_F(FormatTest, RemovesEmptyLines) { "\n" "};")); - // Don't remove empty lines at the start of namespaces. + // Don't remove empty lines at the start of namespaces or extern "C" blocks. EXPECT_EQ("namespace N {\n" "\n" "int i;\n" @@ -197,6 +197,29 @@ TEST_F(FormatTest, RemovesEmptyLines) { "int i;\n" "}", getGoogleStyle())); + EXPECT_EQ("extern /**/ \"C\" /**/ {\n" + "\n" + "int i;\n" + "}", + format("extern /**/ \"C\" /**/ {\n" + "\n" + "int i;\n" + "}", + getGoogleStyle())); + + // ...but do keep inlining and removing empty lines for non-block extern "C" + // functions. + verifyFormat("extern \"C\" int f() { return 42; }", getGoogleStyle()); + EXPECT_EQ("extern \"C\" int f() {\n" + " int i = 42;\n" + " return i;\n" + "}", + format("extern \"C\" int f() {\n" + "\n" + " int i = 42;\n" + " return i;\n" + "}", + getGoogleStyle())); // Remove empty lines at the beginning and end of blocks. EXPECT_EQ("void f() {\n" |