llvm / llvm-project

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

[clang-format]: obey BlockIndent for templates #55339

Open igagis opened 2 years ago

igagis commented 2 years ago

to reproduce

.clang-format

AlignAfterOpenBracket: BlockIndent
AllowAllArgumentsOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
BinPackArguments: 'false'
BinPackParameters: 'false'
ColumnLimit: '120'
ContinuationIndentWidth: '1'
IndentWidth: '1'
Language: Cpp
Standard: Cpp11
TabWidth: '1'
UseCRLF: 'false'
UseTab: ForContinuationAndIndentation

main.cpp:

void function(int asdfasdfsdhgfjhksdgfjkhsd, int sdlfsdkljahgdfklsjhgdf, int sadlkghjasdlkghjfd, int sadlkghjasdlkghjfd, int sadlkghjasdlkghjfd, int sadlkghjasdlkghjfd);

typedef typename std::conditional<
func_one_arg,typename type_or_void<std::invoke_result<F, func_arg_type>>::type,
typename type_or_void<std::invoke_result<F, func_arg_type, size_t>>::type
>::type func_return_type;

expected result

void function(
    int asdfasdfsdhgfjhksdgfjkhsd,
    int sdlfsdkljahgdfklsjhgdf,
    int sadlkghjasdlkghjfd,
    int sadlkghjasdlkghjfd,
    int sadlkghjasdlkghjfd,
    int sadlkghjasdlkghjfd
);

typedef typename std::conditional<
    func_one_arg,
    typename type_or_void<std::invoke_result<F, func_arg_type>>::type,
    typename type_or_void<std::invoke_result<F, func_arg_type, size_t>>::type
>::type func_return_type;

actual result

void function(
    int asdfasdfsdhgfjhksdgfjkhsd,
    int sdlfsdkljahgdfklsjhgdf,
    int sadlkghjasdlkghjfd,
    int sadlkghjasdlkghjfd,
    int sadlkghjasdlkghjfd,
    int sadlkghjasdlkghjfd
);

typedef typename std::conditional<
    func_one_arg,
    typename type_or_void<std::invoke_result<F, func_arg_type>>::type,
    typename type_or_void<std::invoke_result<F, func_arg_type, size_t>>::type>::type func_return_type;

As one can see, closing ) for function is moved to a new line, but closing > for template is not moved to the new line.

version

$ clang-format-14 --version
Debian clang-format version 14.0.1-++20220426012052+0e27d08cdeb3-1~exp1~20220426132142.127
llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-format

mydeveloperday commented 2 years ago

but

    typename type_or_void<std::invoke_result<F, func_arg_type, size_t>>::type>::type func_return_type;

is not 120 why do you expect it to break between type and > ?

igagis commented 2 years ago

Because of the

AlignAfterOpenBracket: BlockIndent

option, same way it broke before ); in the function declaration in the sample code snippet above.