[PATCH] D14188: Format: support inline namespaces

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 29 15:15:13 PDT 2015


compnerd created this revision.
compnerd added a reviewer: djasper.
compnerd added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

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.

http://reviews.llvm.org/D14188

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

Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2192,6 +2192,13 @@
                    "}    // 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"
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1367,7 +1367,8 @@
 
   const FormatToken &InitialToken = *FormatTok;
   nextToken();
-  if (FormatTok->Tok.is(tok::identifier))
+  while (FormatTok->Tok.is(tok::identifier) ||
+         FormatTok->Tok.is(tok::coloncolon))
     nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
     if (ShouldBreakBeforeBrace(Style, InitialToken))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14188.38768.patch
Type: text/x-patch
Size: 1140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151029/4e8b5b32/attachment.bin>


More information about the cfe-commits mailing list