[cfe-dev] Clang-format Inquiry - Member Alignment

Corey Lucier via cfe-dev cfe-dev at lists.llvm.org
Fri Sep 21 04:25:30 PDT 2018


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.

From: Owen Pan <owenpiano at gmail.com>
Date: Wednesday, September 19, 2018 at 10:05 PM
To: "clucier at adobe.com" <clucier at adobe.com>
Cc: "cfe-dev at lists.llvm.org" <cfe-dev at lists.llvm.org>
Subject: Re: [cfe-dev] Clang-format Inquiry - Member Alignment

On Wed, Sep 19, 2018 at 11:34 AM Corey Lucier via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180921/9640944d/attachment.html>


More information about the cfe-dev mailing list