Issue |
89759
|
Summary |
[clang-format] Incorrect space before curly brace in enum definition enclosed in `#ifdef`, with earlier `#else` branch
|
Labels |
clang-format
|
Assignees |
|
Reporter |
akien-mga
|
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)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs