Skip to content

Format struct/class-like macros to preserve semicolon at the end #95418

Closed
@Alexolut

Description

@Alexolut

I have macro like this

#define STRUCT(TYPE) struct TYPE : public Base

that is used as the following:

STRUCT(MyName) {
    // a lot of members (functions, data)
};

I would like to leave the code above as-is after clang-formating.

In particular I have following options in my .clang-format file:

BraceWrapping:
  AfterControlStatement: Never
# ...
RemoveSemicolon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
  AfterControlStatements: true
# ...

The only way I found to preserve semicolon here is to add macro STRUCT to the list of IfMacros and disable space for them:

IfMacros:
  - STRUCT
SpaceBeforeParensOptions:
  AfterIfMacros:   false

But to be fair STRUCT is not an IfMacro. It's more likely TypenameMacros, but unfortunately I didn't find how to achieve that with TypenameMacros. What am I missing? I use LLVM 18.1.7

Metadata

Metadata

Assignees

Labels

clang-formatinvalid-code-generationTool (e.g. clang-format) produced invalid code that no longer compiles

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions