From bf7613d2e7bad2fb6db6570a4211c673deadb19a Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Tue, 6 Jul 2010 13:54:21 +0200
Subject: [PATCH] C++ indenter: Add special case rule for indenting enums.

So you now get
enum A { a = 2,
         b = 3,
       };
---
 src/plugins/cpptools/cppcodeformatter.cpp             | 11 ++++++++---
 .../cplusplus/codeformatter/tst_codeformatter.cpp     |  4 ++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp
index 0eb40bf4e91..582293ff10c 100644
--- a/src/plugins/cpptools/cppcodeformatter.cpp
+++ b/src/plugins/cpptools/cppcodeformatter.cpp
@@ -937,18 +937,23 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
 
     case class_open:
     case enum_open:
-    case defun_open:
+    case defun_open: {
         // undo the continuation indent of the parent
         *savedIndentDepth = parentState.savedIndentDepth;
 
-        if (firstToken)
+        bool followedByData = (!lastToken && !tokenAt(tokenIndex() + 1).isComment());
+        if (firstToken || followedByData)
             *savedIndentDepth = tokenPosition;
 
         *indentDepth = *savedIndentDepth;
 
-        if (m_indentDeclarationMembers)
+        if (followedByData) {
+            *indentDepth = column(tokenAt(tokenIndex() + 1).begin());
+        } else if (m_indentDeclarationMembers) {
             *indentDepth += m_indentSize;
+        }
         break;
+    }
 
     case substatement_open:
         if (firstToken) {
diff --git a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
index 3960de86f39..f604deee9c7 100644
--- a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
+++ b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
@@ -602,6 +602,10 @@ void tst_CodeFormatter::braceList()
          << Line("    a,")
          << Line("    b,")
          << Line("};")
+         << Line("enum Foo { a = 2,")
+         << Line("           a = 3,")
+         << Line("           b = 4")
+         << Line("         };")
          << Line("void foo () {")
          << Line("    int[] a = { foo, bar, ")
          << Line("            car };")
-- 
GitLab