[cfe-users] Questions about clang-format for specific formatting rules

Robert Dailey rcdailey.lists at gmail.com
Thu Oct 16 14:40:09 PDT 2014


I just started taking a look at Clang-Format on Windows using clang
3.6 and I have a few questions concerning formatting rules.

1. Is there a way to force constructor member initiailizer lists to
always use 1 line per member? Example:

Foo::Foo()
    : m_member1(1)
    , m_member2(2)
{}

2. The coding standard we use on the project I am involved in requires
that class indentation be relative to the indentation of the access
specifiers. For example:

class Foo
{
    public:
        Foo();
};

Basically if an access specifier is provided, it follows the normal
indent width (4 in this case). Everything *after* the access specifier
is indented relative to the indentation of the specifier before it (so
actually it would be indented twice). If there are no access
specifiers in a class, indentation goes back to the normal 1 indent.

3. When the parameters of a function exceed the length of the line,
I'd like to see a way to make the parameters get their own dedicated
lines indented 1 level from the start of the function header. For
example:

// Priority 1: All fits on one line
void Foo::SomeFunction(int longparam1, int longparam2, int longparam3);

// Priority 2: No room, try 1 carriage return:
void Foo::SomeFunction(
    int longparam1, int longparam2, int longparam3);

// Priority 3: No room for priority 2, so each gets its own line
void Foo::SomeFunction(
    int longparam1,
    int longparam2,
    int longparam3);

4. Is there a way to make nested namespaces follow this formatting style?

namespace Outter {
namespace Inner {

class Foo;

}} // namespace Outter::Inner

Notice the closing braces are collectively placed on the same line.
Also none of the namespaces have indentation.

Thanks in advance!



More information about the cfe-users mailing list