Issue 169376
Summary clang-format formats {# if}/{if...else}/{#endif}/{if}/{statement} sequence wrong
Labels clang-format
Assignees
Reporter nabijaczleweli
    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 either
```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)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to