[llvm-bugs] [Bug 47571] New: clang-format: cannot correctly format the C source code with CPP keywords.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 17 23:42:54 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47571

            Bug ID: 47571
           Summary: clang-format: cannot correctly format the C source
                    code with CPP keywords.
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: shanyaoxing12 at outlook.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

This is my configuration file:

```
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AllowShortIfStatementsOnASingleLine: false
BasedOnStyle: LLVM
BreakBeforeBraces: WebKit
ColumnLimit: 0
IndentWidth: 4
IndentCaseLabels: false
Language: Cpp
TabWidth: 4
UseTab: Never
```

This is part of my code, it has been formatted:

```c
/* linkedlist.h */
#ifndef LINKEDLIST_H
#define LINKEDLIST_H

typedef struct node *link;
struct node {
    unsigned char item;
    link next;
};

link make_node(unsigned char item);
void free_node(link p);
link search(unsigned char key);
void insert(link p);
void delete (link p);
void traverse(void (*visit)(link));
void destroy(void);
void push(link p);
link pop(void);

#endif
```

In theory, my `delete` function declaration should be formatted as: `void
delete(link p)`;
However, the formatter added a space between `delete` and `(`. This seems to
treat my `delete` signature as a keyword.
This is wrong for C code.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200918/c9a6a0e3/attachment.html>


More information about the llvm-bugs mailing list