From: Daniel Jasper Date: Sun, 8 May 2016 18:12:22 +0000 (+0000) Subject: clang-format: Support enum type template arguments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a350eed549b6f100ebc6abefde315f565231f1f6;p=clang clang-format: Support enum type template arguments. Before: template class A { public : E *f(); }; After: template class A { public: E *f(); }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268878 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index c6bf71adbf..c8e4cc4a1b 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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 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()) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 0f785705d9..470e989262 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5381,6 +5381,10 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { verifyFormat("template // T can be A, B or C.\n" "struct C {};", AlwaysBreak); + verifyFormat("template class A {\n" + "public:\n" + " E *f();\n" + "};"); } TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {