Fixes indent in linkage specification blocks.
authorManuel Klimek <klimek@google.com>
Mon, 21 Jan 2013 14:32:05 +0000 (14:32 +0000)
committerManuel Klimek <klimek@google.com>
Mon, 21 Jan 2013 14:32:05 +0000 (14:32 +0000)
We now indent:
extern "C" {
int a;
}

without additional indent inside the extern "C" block.

llvm-svn: 173045

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

index 7f9e97e..f1d08a6 100644 (file)
@@ -311,6 +311,18 @@ void UnwrappedLineParser::parseStructuralElement() {
   case tok::kw_return:
     parseReturn();
     return;
+  case tok::kw_extern:
+    nextToken();
+    if (FormatTok.Tok.is(tok::string_literal)) {
+      nextToken();
+      if (FormatTok.Tok.is(tok::l_brace)) {
+        parseBlock(0);
+        addUnwrappedLine();
+        return;
+      }
+    }
+    // In all other cases, parse the declaration.
+    break;
   default:
     break;
   }
index f8c454b..f67cd8c 100644 (file)
@@ -526,6 +526,10 @@ TEST_F(FormatTest, FormatsNamespaces) {
                "void f() { f(); }");
 }
 
+TEST_F(FormatTest, FormatsExternC) {
+  verifyFormat("extern \"C\" {\nint a;");
+}
+
 TEST_F(FormatTest, FormatTryCatch) {
   // FIXME: Handle try-catch explicitly in the UnwrappedLineParser, then we'll
   // also not create single-line-blocks.