From 046b9306d4b39b48dc74a84ce40a7f6931aea7d4 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Wed, 6 Feb 2013 16:08:09 +0000 Subject: [PATCH] Much semicolon after namespaces. We now leave the semicolon in the line of the closing brace in: namespace { ... }; llvm-svn: 174514 --- clang/lib/Format/UnwrappedLineParser.cpp | 4 ++++ clang/unittests/Format/FormatTest.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index f79cc71..5af60a4 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -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. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index c2e845b..4dc6ea7 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) { -- 2.7.4