c++

I'm trying to configure clang-format so that usually braces will start on their own line:

void func()
{
    if (...)
    {
        printf("Ta Dan");
    }
}

But I want it to be so when braces are empty, it will be kept in a single line. (Mainly used for ctors):

Bar::Bar(int val):
    _val(val)
{}

currently it will look like this:

Bar::Bar(int val):
    _val(val)
{
}

Any ideas?

(Edited to make the situation clearer)


我使用了“AllowShortFunctionsOnASingleLine”:true和“BreakBeforeBraces”:“Allman”的组合,以便在声明空构造函数时将它放到一行中。


UPDATE: Hurray! It is now possible with Clang 5.0 or later with custom BreakBeforeBraces . See SplitEmptyFunction in the documentation.

Configuration example:

BreakBeforeBraces: Custom
BraceWrapping:
  SplitEmptyFunction: false

Unfortunately, it is not possible to achieve with Clang 4.0 the current clang-format options (as of Clang 4.0).

Source: I had the same question. After studying every documented option, and many tweaking attempts, I could not achieve this. In my experience, clang-format is just not as flexible as one would hope. As soon as you want to step out of the predefined styles and tweak things to your liking, it just does not cut it.

链接地址: http://www.djcxy.com/p/93586.html

上一篇: 无法管道输出Hadoop命令

下一篇: C ++