Skip to content

clang-format: cannot correctly format the C source code with CPP keywords. #46915

@dsyx

Description

@dsyx
Bugzilla Link 47571
Version unspecified
OS All

Extended Description

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:

/* 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorbugzillaIssues migrated from bugzillacclang-formatgood first issuehttps://github.com/llvm/llvm-project/contribute

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions