diff options
author | Daniel Jasper <djasper@google.com> | 2016-05-08 18:12:22 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2016-05-08 18:12:22 +0000 |
commit | a7900adf41f4fefefb71fa475e9728b3bd7a779d (patch) | |
tree | 2f3547da374243afb5cfa5bf5ccd27cf06c604b7 | |
parent | 4a9d32c5bab34d5ae64f521ea84470721edeb128 (diff) | |
download | bcm5719-llvm-a7900adf41f4fefefb71fa475e9728b3bd7a779d.tar.gz bcm5719-llvm-a7900adf41f4fefefb71fa475e9728b3bd7a779d.zip |
clang-format: Support enum type template arguments.
Before:
template <enum E> class A { public : E *f(); };
After:
template <enum E> class A {
public:
E *f();
};
llvm-svn: 268878
-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) { |