llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.52k stars 11.79k forks source link

Add option to break before trailing return type #37059

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 37711
Version 6.0
OS Linux
Reporter LLVM Bugzilla Contributor
CC @mloskot

Extended Description

I'm having a number of issues trying to get clang-format to behave reasonably on https://github.com/Kitware/kwiver/blob/303a11ebb43c020ab8e48b6ef70407b460dba46b/vital/range/defs.h, using https://gist.github.com/mwoehlke-kitware/d8ef9466df5096a035059938aef2948d.

For this RFE, specifically, I would like an option to force a break after a the closing brace of a function's parameter list and a trailing return type specifier. For example:

// Current (unwanted) static auto end_helper( Range const& range ) -> decltype( end( range ) )

// Desired static auto end_helper( Range const& range ) -> decltype( end( range ) )

llvmbot commented 3 years ago

There are a variety of combinations that can be used with trailing return types and currently clang-format doesn't behave or have any real control on how to format this in an useful way.

We can have declarations in headers:

class A
{
private:
  auto Initialize() -> bool;
}

or implementations:

auto
  Initialize()
  -> bool
{
}

In lambdas, etc.

I'd like to be able to set an offset/alignment.

mloskot commented 5 years ago

AFAICT, upgrade to clang-format 7 should solve the problem, see http://lists.llvm.org/pipermail/cfe-users/2018-November/001421.html

There is one subtle issue though, see bug 42835

Zingam commented 2 years ago

In a general case I think that more options to control the formatting of the trailing return types would be nice like aligning return types of declarations which a close to each other like:

    auto func1() const          -> int;
    auto long_name_func() const -> int;

    auto func2()        const -> int;
    auto funcLongName() const -> int;
paul-reilly commented 5 months ago

I'd also like to see more control over formatting trailing return types. My wish would be to have independent continuation indentation. e.g. here with a continuation indentation of 8:

auto my_function(long::namespacing::typename foo, longer::namespacing::typename bar,
        longest::namespacing::typename baz)
        -> return_type
{ }

// ... to a independently configurable indentation for trailing returns, in this case 2 ...

auto my_function(long::namespacing::typename foo, longer::namespacing::typename bar,
        longest::namespacing::typename baz)
  -> return_type
{ }

// ... and for function declarations, perhaps also separately configurable

auto my_function()
  -> return_type;

I don't know if somebody would like to quickly edit this topic title with a [clang-format] to improve discoverability.