diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp
index 0eb40bf4e91b38de286baffeb4d4d11c5b1df4f8..582293ff10c6979c42979b7bc6903d559fd8bacd 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 3960de86f39e1fb573f9ae5d1742529c93a0f387..f604deee9c7d40b39a68e6f4eab1268f34b3c2a3 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 };")