]> granicus.if.org Git - clang/commitdiff
Format: support inline namespaces
authorSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 30 Oct 2015 05:07:56 +0000 (05:07 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 30 Oct 2015 05:07:56 +0000 (05:07 +0000)
Correct handling for C++17 inline namespaces.  We would previously fail to
identify the inline namespaces as a namespace name since multiple ones may be
concatenated now with C++17.

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

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

index 634dbe970845e6283e5cdd9dc0591f71f9516639..ad548217b41409e11c72771c553af9474e7cb0ed 100644 (file)
@@ -1367,7 +1367,7 @@ void UnwrappedLineParser::parseNamespace() {
 
   const FormatToken &InitialToken = *FormatTok;
   nextToken();
-  if (FormatTok->Tok.is(tok::identifier))
+  while (FormatTok->isOneOf(tok::identifier, tok::coloncolon))
     nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
     if (ShouldBreakBeforeBrace(Style, InitialToken))
index eaa31b1ebfaa06f0f24d7fa1ecbae312c656f60e..1c68d67956ca9c724b69483bd2b04b882f753a2f 100644 (file)
@@ -2192,6 +2192,13 @@ TEST_F(FormatTest, FormatsNamespaces) {
                    "}    // my_namespace\n"
                    "#endif    // HEADER_GUARD"));
 
+  EXPECT_EQ("namespace A::B {\n"
+            "class C {};\n"
+            "}",
+            format("namespace A::B {\n"
+                   "class C {};\n"
+                   "}"));
+
   FormatStyle Style = getLLVMStyle();
   Style.NamespaceIndentation = FormatStyle::NI_All;
   EXPECT_EQ("namespace out {\n"