]> granicus.if.org Git - clang/commitdiff
Formatter: parse and format inline namespaces like regular namespaces
authorDmitri Gribenko <gribozavr@gmail.com>
Sun, 30 Dec 2012 21:27:25 +0000 (21:27 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Sun, 30 Dec 2012 21:27:25 +0000 (21:27 +0000)
This changes formatting from:

inline namespace X {
  class A {
  };
}

to:

inline namespace X {
class A {
};
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171266 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6c035b001c78a995ef786c863a27cd48ff8aae66..78a1abdcf8df5d4a027e3fdcfff08aa7f8e46e83 100644 (file)
@@ -100,10 +100,19 @@ void UnwrappedLineParser::parseComments() {
 void UnwrappedLineParser::parseStatement() {
   parseComments();
 
+  int TokenNumber = 0;
   switch (FormatTok.Tok.getKind()) {
   case tok::kw_namespace:
     parseNamespace();
     return;
+  case tok::kw_inline:
+    nextToken();
+    TokenNumber++;
+    if (FormatTok.Tok.is(tok::kw_namespace)) {
+      parseNamespace();
+      return;
+    }
+    break;
   case tok::kw_public:
   case tok::kw_protected:
   case tok::kw_private:
@@ -132,7 +141,6 @@ void UnwrappedLineParser::parseStatement() {
   default:
     break;
   }
-  int TokenNumber = 0;
   do {
     ++TokenNumber;
     switch (FormatTok.Tok.getKind()) {
index 43003befb673a170a75b4d7b2fbe8b54a767c0c4..b719acfabc6d98b14405140d8eea1abeb2c740b6 100644 (file)
@@ -349,6 +349,13 @@ TEST_F(FormatTest, FormatsNamespaces) {
                "  f();\n"
                "}\n"
                "}");
+  verifyFormat("inline namespace X {\n"
+               "class A {\n"
+               "};\n"
+               "void f() {\n"
+               "  f();\n"
+               "}\n"
+               "}");
   verifyFormat("using namespace some_namespace;\n"
                "class A {\n"
                "};\n"