clang-format: Better support functions with elaborated enum return types.

Before, this wasn't formatted properly:
  enum ::C f() {
    return a;
  }

llvm-svn: 240021
This commit is contained in:
Daniel Jasper 2015-06-18 15:45:17 +00:00
parent f90346f8f6
commit 47721ac75d
2 changed files with 15 additions and 1 deletions

View File

@ -1491,6 +1491,8 @@ void UnwrappedLineParser::parseEnum() {
while (FormatTok->Tok.getIdentifierInfo() ||
FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
tok::greater, tok::comma, tok::question)) {
if (FormatTok->is(tok::coloncolon))
nextToken();
nextToken();
// We can have macros or attributes in between 'enum' and the enum name.
if (FormatTok->is(tok::l_paren))

View File

@ -1996,7 +1996,6 @@ TEST_F(FormatTest, FormatsEnum) {
verifyFormat("enum X E {} d;");
verifyFormat("enum __attribute__((...)) E {} d;");
verifyFormat("enum __declspec__((...)) E {} d;");
verifyFormat("enum X f() {\n a();\n return 42;\n}");
verifyFormat("enum {\n"
" Bar = Foo<int, int>::value\n"
"};",
@ -2025,6 +2024,19 @@ TEST_F(FormatTest, FormatsEnum) {
" TWO\n"
"};\n"
"int i;");
// Not enums.
verifyFormat("enum X f() {\n"
" a();\n"
" return 42;\n"
"}");
verifyFormat("enum ::X f() {\n"
" a();\n"
" return 42;\n"
"}");
verifyFormat("enum ns::X f() {\n"
" a();\n"
" return 42;\n"
"}");
}
TEST_F(FormatTest, FormatsEnumsWithErrors) {