Is it possible to force a trailing return type to a new line with clang-format?

Viewed 287

I'm looking a for a way to cause trailing return types to always be put on a new line. I noticed clang format will do this with long declarations, but will not if it's short enough. Is there a way to change this?

Ex.

auto foo() -> std::optional<std::string>
{ 
   // ...
}

Becomes

auto foo()
   -> std::optional<std::string>
{
   // ...
}
1 Answers

Not as far as I am aware (likely because it's a somewhat relatively new feature)

A workaround is to put a comment there:

    auto foo() //
        -> std::optional<std::string>
    { 
       // ...
    }

But seeing as it's not implemented as standard, probably means it's a very uncommon notation, so maybe it's best to stick to the default

Related