Clang-format Inquiry - Member Alignment

Thank you in advance for any assistance, this is my first cfe-dev list post, apologies for any disruption.

We use clang-format to lint our C++ as well as “auto-fix” as necessary.

There is one coding convention which we had to lose given the fact that it seems clang-format doesn’t have any options we can use to allow for it. Specifically C++ class member alignment.

We want to for example be able to format our class members for easier scanning/readability as follows:

TypeA m_memberOne;

LongTypeB* m_memberTwo = nullptr;

bool m_someFlag = false;

Unfortunately if we for example make use of AlignConsecutiveDeclarations local method definitions become aligned as well as locally declared functions, etc.

Is there any current mechanism to allow for class member declaration alignment and validation?

Best,

Corey L.

Thank you in advance for any assistance, this is my first cfe-dev list post, apologies for any disruption.

We use clang-format to lint our C++ as well as “auto-fix” as necessary.

There is one coding convention which we had to lose given the fact that it seems clang-format doesn’t have any options we can use to allow for it. Specifically C++ class member alignment.

We want to for example be able to format our class members for easier scanning/readability as follows:

TypeA m_memberOne;

LongTypeB* m_memberTwo = nullptr;

bool m_someFlag = false;

Unfortunately if we for example make use of AlignConsecutiveDeclarations local method definitions become aligned as well as locally declared functions, etc.

Can you use a code snippet to elaborate what you mean and want here? Are you referring to member functions defined and declared in the class declaration, respectively?

Is there any current mechanism to allow for class member declaration alignment and validation?

What does validation mean?

Thanks,

Owen

Thanks Owen.

Given a class definition:

class Rectangle {

public:

Rectangle(int,int);

int area();

private:

int m_width = 0;

int m_height = 0

double m_cornerRadius = 0;

};

I’m speaking of aligning the class members only (w/h/cornerradius above).

We use clang-format to check that all developers code matches our coding conventions before they check-in, that’s all I meant by validation. If their code doesn’t match the rules we’ve setup, we use clang-format to auto-fix. The problem is with AlignConsecutiveDeclarations it aligns these but also many other things (basically any declaration), which is not what we want.