Fixes PR 17106 (explicitly typed enums are formatted differently).
Before:
enum X : int { A, B, C };
After:
enum X : int {
A,
B,
C
};
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190054 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 5029bd6..766e1d8 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -1035,9 +1035,7 @@
if (FormatTok->Tok.is(tok::kw_class) ||
FormatTok->Tok.is(tok::kw_struct))
nextToken();
- if (FormatTok->Tok.is(tok::identifier) ||
- FormatTok->Tok.is(tok::kw___attribute) ||
- FormatTok->Tok.is(tok::kw___declspec)) {
+ while (FormatTok->Tok.getIdentifierInfo() || FormatTok->Tok.is(tok::colon)) {
nextToken();
// We can have macros or attributes in between 'enum' and the enum name.
if (FormatTok->Tok.is(tok::l_paren)) {
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 2307b03..6d953eb 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1573,6 +1573,13 @@
verifyFormat("enum class X f() {\n a();\n return 42;\n}");
}
+TEST_F(FormatTest, FormatsEnumTypes) {
+ verifyFormat("enum X : int {\n"
+ " A,\n"
+ " B\n"
+ "};");
+}
+
TEST_F(FormatTest, FormatsBitfields) {
verifyFormat("struct Bitfields {\n"
" unsigned sClass : 8;\n"