<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/89759>89759</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Incorrect space before curly brace in enum definition enclosed in `#ifdef`, with earlier `#else` branch
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-format
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          akien-mga
      </td>
    </tr>
</table>

<pre>
    Reproduced in: clang-format 17.0.6 (Fedora 39)
I couldn't test clang-format 18.1.4 yet as it's not in Fedora 39 and there are no x86_64-linux-gnu builds currently.
I'll update this report when I get to upgrade to Fedora 40 with LLVM 18.

The issue title is a bit convoluted, but so is the reproducer we found in the wild in https://github.com/godotengine/godot/pull/89734/files#r1561531093

The code is easier to understand that trying to describe it, so:
```cpp
#ifdef DEBUG_ENABLED
// Remove #else to fix formatting bug.
#else
#endif

class RenderingServer : public Object {
#ifndef DISABLE_DEPRECATED
  enum Features{
 FEATURE_SHADERS,
      FEATURE_MULTITHREADED,
 };
#endif
};
```

This snipped is formatted by clang-format 17.0.6 with the default LLVM style.

As you can see, it's missing a space between `enum Features` and the opening curly brace that defines it. The enum values are also indented twice instead of once.

Removing the `#else` branch at the top of the file solves the issue:
```cpp
#ifdef DEBUG_ENABLED
#endif

class RenderingServer : public Object {
#ifndef DISABLE_DEPRECATED
enum Features {
 FEATURE_SHADERS,
    FEATURE_MULTITHREADED,
 };
#endif
};
```

Likewise, removing the `#ifndef DISABLE_DEPRECATED` enclosing the enum definition solves the problem.

Minimal reproducer with the above code: 
[clang-format-ifdef-enum-bug.zip](https://github.com/llvm/llvm-project/files/15077355/clang-format-ifdef-enum-bug.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VluP4jYU_jXm5QiUOAkhDzwwA3RHmm0rZravIyc-Sdw1duQLLP31lZ3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