Much semicolon after namespaces.
authorManuel Klimek <klimek@google.com>
Wed, 6 Feb 2013 16:08:09 +0000 (16:08 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 6 Feb 2013 16:08:09 +0000 (16:08 +0000)
We now leave the semicolon in the line of the closing brace in:
namespace {
...
};

llvm-svn: 174514

clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

index f79cc71..5af60a4 100644 (file)
@@ -505,6 +505,10 @@ void UnwrappedLineParser::parseNamespace() {
     nextToken();
   if (FormatTok.Tok.is(tok::l_brace)) {
     parseBlock(/*MustBeDeclaration=*/ true, 0);
+    // Munch the semicolon after a namespace. This is more common than one would
+    // think. Puttin the semicolon into its own line is very ugly.
+    if (FormatTok.Tok.is(tok::semi))
+      nextToken();
     addUnwrappedLine();
   }
   // FIXME: Add error handling.
index c2e845b..4dc6ea7 100644 (file)
@@ -617,6 +617,15 @@ TEST_F(FormatTest, FormatsNamespaces) {
   verifyFormat("using namespace some_namespace;\n"
                "class A {\n};\n"
                "void f() { f(); }");
+
+  // This code is more common than we thought; if we
+  // layout this correctly the semicolon will go into
+  // its own line, which is undesireable.
+  verifyFormat("namespace {\n};");
+  verifyFormat("namespace {\n"
+               "class A {\n"
+               "};\n"
+               "};");
 }
 
 TEST_F(FormatTest, FormatsExternC) {