r240021 - clang-format: Better support functions with elaborated enum return types.
Daniel Jasper
djasper at google.com
Thu Jun 18 08:45:17 PDT 2015
Author: djasper
Date: Thu Jun 18 10:45:17 2015
New Revision: 240021
URL: http://llvm.org/viewvc/llvm-project?rev=240021&view=rev
Log:
clang-format: Better support functions with elaborated enum return types.
Before, this wasn't formatted properly:
enum ::C f() {
return a;
}
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=240021&r1=240020&r2=240021&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Jun 18 10:45:17 2015
@@ -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))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=240021&r1=240020&r2=240021&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jun 18 10:45:17 2015
@@ -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) {
More information about the cfe-commits
mailing list