Skip to content

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

@nabijaczleweli

Description

@nabijaczleweli

I got this from clang-format --style=LLVM -i a.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

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

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-1exp120250519112844.1459)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions