Fix parsing of variable declarations directly after a class / struct.
Previous indent:
class A {
}
a;
void f() {
};
With this patch:
class A {
} a;
void f() {
}
;
The patch introduces a production for classes and structs, and parses
the rest of the line to the semicolon after the class scope.
This allowed us to remove a long-standing wart in the parser that would
just much the semicolon after any block.
Due to this suboptimal formating some tests were broken.
Some unrelated formatting tests broke; those hit a bug in the ast
printing, and need to be fixed separately.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171761 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index d4490dd..2ba4765 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -332,6 +332,13 @@
"};");
}
+TEST_F(FormatTest, FormatsVariableDeclarationsAfterStructOrClass) {
+ verifyFormat("class A {\n"
+ "} a, b;");
+ verifyFormat("struct A {\n"
+ "} a, b;");
+}
+
TEST_F(FormatTest, FormatsEnum) {
verifyFormat("enum {\n"
" Zero,\n"
@@ -624,7 +631,7 @@
TEST_F(FormatTest, BreaksDesireably) {
verifyFormat("if (aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
" aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
- " aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa)) {\n};");
+ " aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa)) {\n}");
verifyFormat(
"aaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
@@ -974,14 +981,14 @@
"int qwerty;");
verifyFormat("public\n"
"B {\n"
- "};");
+ "}");
verifyFormat("public\n"
"{\n"
- "};");
+ "}");
verifyFormat("public\n"
"B {\n"
" int x;\n"
- "};");
+ "}");
}
TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
@@ -990,16 +997,16 @@
TEST_F(FormatTest, IncorrectCodeDoNoWhile) {
verifyFormat("do {\n"
- "};");
+ "}");
verifyFormat("do {\n"
- "};\n"
+ "}\n"
"f();");
verifyFormat("do {\n"
"}\n"
"wheeee(fun);");
verifyFormat("do {\n"
" f();\n"
- "};");
+ "}");
}
TEST_F(FormatTest, DoesNotTouchUnwrappedLinesWithErrors) {