Skip to content

Add clang-format option for formatting single statement function on one line with braces #145161

@void2012

Description

@void2012

Hello! I want to format my C++ code with custom formatting style specified in .clang-format file. The clang-format documentation says there is an option that allows to put short function bodies on the same line with functions.
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#allowshortfunctionsonasingleline
However, this is not what I want. I want the function body braces to be put on the same line with function body itself, not the whole thing with signature.

With AllowShortFunctionsOnASingleLine: All:

inline const char* GetBuildingName(TTownType townType, type_building_id buildingId) { return FASTCALL_2(const char*, 0x460CC0, townType, buildingId); } // everything on the same line, ugly

With AllowShortFunctionsOnASingleLine: None:

inline const char* GetBuildingName(TTownType townType, type_building_id buildingId)
{ 
return FASTCALL_2(const char*, 0x460CC0, townType, buildingId); // I need it on the single line
}

Desired behavior:

inline const char* GetBuildingName(TTownType townType, type_building_id buildingId)
{ return FASTCALL_2(const char*, 0x460CC0, townType, buildingId); } // what I want, but only for single-line body functions

It would be also great to have such an option for structs/classes that contain only a single line of code inside their bodies. Thanks!

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions