]> granicus.if.org Git - clang/commitdiff
clang-format: Support enum type template arguments.
authorDaniel Jasper <djasper@google.com>
Sun, 8 May 2016 18:12:22 +0000 (18:12 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 8 May 2016 18:12:22 +0000 (18:12 +0000)
Before:
  template <enum E> class A { public : E *f(); };

After:
  template <enum E> class A {
  public:
    E *f();
  };

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

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

index c6bf71adbf1ac702652f930c5057bde5a4a6c853..c8e4cc4a1b627a98fcbcfbd51f86f6d773ccee9e 100644 (file)
@@ -902,6 +902,7 @@ void UnwrappedLineParser::parseStructuralElement() {
     break;
   }
   do {
+    const FormatToken *Previous = getPreviousToken();
     switch (FormatTok->Tok.getKind()) {
     case tok::at:
       nextToken();
@@ -909,6 +910,12 @@ void UnwrappedLineParser::parseStructuralElement() {
         parseBracedList();
       break;
     case tok::kw_enum:
+      // Ignore if this is part of "template <enum ...".
+      if (Previous && Previous->is(tok::less)) {
+        nextToken();
+        break;
+      }
+
       // parseEnum falls through and does not yet add an unwrapped line as an
       // enum definition can start a structural element.
       if (!parseEnum())
index 0f785705d9efecb6ca5e23bf5d05afeafad14762..470e989262cb9021cbf41beb6446a6d2dedc77de 100644 (file)
@@ -5381,6 +5381,10 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
   verifyFormat("template <typename T> // T can be A, B or C.\n"
                "struct C {};",
                AlwaysBreak);
+  verifyFormat("template <enum E> class A {\n"
+               "public:\n"
+               "  E *f();\n"
+               "};");
 }
 
 TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {