llvm / llvm/llvm-project

clang-format formats {#if}/{if...else}/{#endif}/{if}/{statement} sequence wrong

Open
#169,376 1 comment 0 reactions 0 assignees View on GitHub
clang-format
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I got this from `clang-format --style=LLVM -i a.c`:
```c
void a() {
#if __linux__
if (addr.sun_path[0] == '@') // linux abstract socket
addr.sun_path[0] = '\0';
else
#endif
if (stat(unix, &sb) && S_ISSOCK(sb.st_mode))
unlink(unix);
}
```
the correct formatting would be
```c
void a() {
#if __linux__
if (addr.sun_path[0] == '@') // linux abstract socket
addr.sun_path[0] = '\0';
else
#endif
if (stat(unix, &sb) && S_ISSOCK(sb.st_mode))
unlink(unix);
}
```
or maybe
```c
void a() {
#if __linux__
if (addr.sun_path[0] == '@') // linux abstract socket
addr.sun_path[0] = '\0';
else
#endif
if (stat(unix, &sb) && S_ISSOCK(sb.st_mode))
unlink(unix);
}
```
but definitely not the first one.

Debian clang-format version 21.0.0 (++20250519112653+d0ee35851bb9-1~exp1~20250519112844.1459)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.