diff options
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 7 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index c6bf71adbf1..c8e4cc4a1b6 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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 <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()) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 0f785705d9e..470e989262c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) { |