]> granicus.if.org Git - clang/commitdiff
Fixes PR 17106 (explicitly typed enums are formatted differently).
authorManuel Klimek <klimek@google.com>
Thu, 5 Sep 2013 15:34:55 +0000 (15:34 +0000)
committerManuel Klimek <klimek@google.com>
Thu, 5 Sep 2013 15:34:55 +0000 (15:34 +0000)
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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 5029bd689bcb13625932b07dcbf9b0c2b0182cce..766e1d8d92233191ae97e8994c5c137425d74a7b 100644 (file)
@@ -1035,9 +1035,7 @@ void UnwrappedLineParser::parseEnum() {
   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)) {
index 2307b03f51fdb0f9c5894f99cb44bfd6732d58f2..6d953eb3018e4731399f1b0ef044e147ccaf9527 100644 (file)
@@ -1573,6 +1573,13 @@ TEST_F(FormatTest, FormatsEnumClass) {
   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"