Skip to content

[clang-format] Formatting a C file only works with Cpp formatting settings #145249

Closed as not planned
@hueychen27

Description

@hueychen27

Let this be the file, unformatted.c, to be formatted in the examples:

 int      main(int  argc , char  * argv [] ) {
     int * thing;
    int *eee;
}

This will not format the C code at all as clang-format returns Configuration file(s) do(es) not support C++:

---
Language: C

IndentWidth: 9
PointerAlignment: Left

Adding BaseOnStyle: LLVM to the top of the file will run without an error, but the custom settings defined are ignored:

BasedOnStyle: LLVM
---
Language: C

IndentWidth: 9
PointerAlignment: Left

Formatted file:

int main(int argc, char *argv[]) {
  int *thing;
  int *eee;
}

For some reason, changing Language: C to use Cpp works.

BasedOnStyle: LLVM
---
Language: Cpp

IndentWidth: 9
PointerAlignment: Left

Formatted file:

int main(int argc, char* argv[]) {
         int* thing;
         int* eee;
}

Why is Language: C ignored?

clang-format version:

$ clang-format-21 --version
Debian clang-format version 21.0.0 (++20250612091244+3f0cf742ac4e-1~exp1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-formatobsoleteIssues with old (unsupported) versions of LLVM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions