]> granicus.if.org Git - clang/commitdiff
Allow for nested name specifiers in record declarations.
authorManuel Klimek <klimek@google.com>
Mon, 21 Jan 2013 10:17:14 +0000 (10:17 +0000)
committerManuel Klimek <klimek@google.com>
Mon, 21 Jan 2013 10:17:14 +0000 (10:17 +0000)
Now correctly formats:
class A::B {} n;

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

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

index 3fd1ff9024e8a6729ea049557528a416b9e19919..dffc309a09efe13145eb3866723e200cf43f275e 100644 (file)
@@ -615,7 +615,9 @@ void UnwrappedLineParser::parseRecord() {
     if (FormatTok.Tok.is(tok::l_paren)) {
       parseParens();
     }
-    if (FormatTok.Tok.is(tok::identifier))
+    // The actual identifier can be a nested name specifier.
+    while (FormatTok.Tok.is(tok::identifier) ||
+           FormatTok.Tok.is(tok::coloncolon))
       nextToken();
 
     if (FormatTok.Tok.is(tok::colon)) {
index 1d3463ccfd242dedd7d1cf88bb5d7ef6160af3c3..3c929a3f532c2379edd67519ee5cef38601f6bbb 100644 (file)
@@ -1519,13 +1519,17 @@ TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
 
   // Actual definitions...
   verifyFormat("struct {} n;");
-  verifyFormat("template <template <class T, class Y>, class Z > class X {} n;");
+  verifyFormat(
+      "template <template <class T, class Y>, class Z > class X {} n;");
   verifyFormat("union Z {\n  int n;\n} x;");
   verifyFormat("class MACRO Z {} n;");
   verifyFormat("class MACRO(X) Z {} n;");
   verifyFormat("class __attribute__(X) Z {} n;");
   verifyFormat("class __declspec(X) Z {} n;");
 
+  // Redefinition from nested context:
+  verifyFormat("class A::B::C {} n;");
+
   // Elaborate types where incorrectly parsing the structural element would
   // break the indent.
   verifyFormat("if (true)\n"