Skip to content

[clang-format] wrong formatting when C++ keywords are used as variable name in C #59188

Closed
@kleisauke

Description

@kleisauke

For example:

void test() {
  int *p;
  
  int and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor,
      xor_eq = 1;

  p = ∧
  p = &and_eq;
  p = &bitand;
  p = &bitor;
  p = &compl;
  p = ¬
  p = &not_eq;
  p = ∨
  p = &or_eq;
  p = &xor;
  p = &xor_eq;
}

int main() {
  int *and, *and_eq, *bitand, *bitor, *compl, *not, *not_eq, *or, *or_eq,
      *xor, *xor_eq = 0;
}

Is incorrectly formatted as:

void test() {
  int *p;

  int and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor,
      xor_eq = 1;

  p = ∧
  p = & and_eq ;
  p = &bitand;
  p = & bitor ;
  p = &compl ;
  p = &not ;
  p = & not_eq ;
  p = & or ;
  p = & or_eq ;
  p = &xor;
  p = & xor_eq ;
}

int main() {
  int *and, * and_eq, *bitand, * bitor, *compl, *not, * not_eq, * or, * or_eq,
      *xor, * xor_eq = 0;
}

(note that and, bitand, compl, not and xor is somehow unaffected)

Tested with the latest revision (commit 409f0dc at the time of writing):

$ clang-format --version
clang-format version 16.0.0 (https://github.com/llvm/llvm-project.git 409f0dc4a420db1c6b259d5ae965a070c169d930)
$ clang-format -style=llvm test.c

(For the same reason, the lldb/test/API/lang/c/cpp_keyword_identifiers/main.c file is probably excluded for clang-format)

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