There are a few things blocking me from switching to clang-format. When I have a trailing return type on a lambda that should wrap to the next line there is no space between the arrow and the trailing return type. How can I fix this?
For example this is the output from clang-format for the unformatted version of the same code below
auto func() {
return [.......](auto one, auto long_parameter_list, auto another)
->SomeLongReturnType;
// ^^^^^^^^^^^^^^^^^^^^^ How can I add a space in between those?
}
TL;TR: Upgrade to clang-format 7.0 or later.
The clang-format 7.0 comes with fixes related to the trailing return, so you should be able to achieve the desired formatting:
Before
template <int K, typename E, typename L, int N>
auto ccccccccccccccccccccccc(detail::base<E, L, N>& p) -> std::add_lvalue_reference<E>::type;
After:
template <int K, typename E, typename L, int N>
auto ccccccccccccccccccccccc(detail::base<E, L, N> &p)
-> std::add_lvalue_reference<E>::type;
Related is a subtle issue that clang-format 7 still suffers from https://bugs.llvm.org/show_bug.cgi?id=42835 and it does not indent the breaking of the trailing return if there is typename
used:
Before:
template <int K, typename E, typename L, int N>
auto bbbbbbbbbbbbbbbbbbbbbbb(detail::base<E, L, N>& p) -> typename std::add_lvalue_reference<E>::type;
After:
template <int K, typename E, typename L, int N>
auto bbbbbbbbbbbbbbbbbbbbbbb(detail::base<E, L, N> &p) ->
typename std::add_lvalue_reference<E>::type;
Related mailing list thread: [cfe-users] [clang-format] Trailing return type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With