Search code examples
c++cclang-format

Make clang-format allow return type of function on its own line


I'm trying to figure out if I can use clang-format to automatically format the code for my project. We have a coding style which enforces newlines after the function return type (but only in the definition, not in the declaration). I'd like to encode this in clang-format.

IOW, I want this:

uint32_t
my_function(uint32_t input)
{
    return 0;
}

Not this:

uint32_t my_function(uint32_t input)
{
    return 0;
}

Solution

  • AlwaysBreakAfterDefinitionReturnType(DRTBS_All) If you add that to the .clang-format file that contains all your formatting decisions it should do exactly what you want.