[cfe-dev] clang-format: Proposal for a new style for constructor and initializers line break.

Jean-philippe Dufraigne j.dufraigne at gmail.com
Sun Sep 14 14:47:18 PDT 2014


Thank you very much for your input.

I've done some research and found http://pocoproject.org (
https://github.com/pocoproject/poco
http://www.appinf.com/download/CppCodingStyleGuide.pdf page 27/52) uses it.

For full disclosure, I'm hoping to adopt clang-format for the projects we
develop at work.
The style we use has no indentation for the initializers, this is an option
that already exist in clang-format, and address the style concern you had.
After the patch the following style will be allowed:

Constructor( // Arguments too long to fit on the same line
    SomeArgument some_argument,
    SomeOtherArgument some_other_argument) :
some_argument_(some_argument),
some_other_argument_(some_other_argument)
{
}

I'm new to the process and the tools. I've submitted a very small patch
before, hopefully will be relatively uncontroversial. It updates the test
and should ease the process and clarify the patch for the feature:
http://reviews.llvm.org/D5346
For the feature itself, I'll submit one patch after the process for this
review is completed.

Cheers,
Jean-Philippe.

2014-09-14 10:34 GMT+01:00 Daniel Jasper <djasper at google.com>:

> Not entirely sure what advise you are looking for.
> My thoughts:
> - I am happy to accept a patch provided is has sufficient unit tests
> - I think this should go in as a single patch, I don't see a need for "a
> set of small patches"
> - Personally, I think this style is bad as it makes it harder to
> distinguish wrapped constructor arguments from initializers
> - In particular, how do you indent:
>
> Constructor( // Arguments too long to fit on the same line
>     SomeArgument some_argument,
>     SomeOtherArgument some_other_argument) :
>     some_argument_(some_argument),
>     some_other_argument_(some_other_argument) {
> }
>
> Is this style used in any large project or widely used style guide?
>
> Cheers,
> Daniel
>
>
> On Sun, Sep 14, 2014 at 10:34 AM, Jean-philippe Dufraigne <
> j.dufraigne at gmail.com> wrote:
>
>> Hello,
>>
>> I'm interested in adding support for another style for constructor colon
>> and initializer.
>> An example of the style is above the value BCIS_AfterColonAndComma bellow.
>>
>> BreakConstructorInitializers would replace 'bool
>> BreakConstructorInitializersBeforeComma;' while maintaining backward
>> compatibility, in a similar fashion it was done before.
>>
>> I have the prototype for the code and would be really happy to finalize
>> it and contribute a set of small patches.
>>
>> Please let me know if this something that fits with the project and if
>> you have any advice.
>> Best Regards,
>> Jean-Philippe
>>
>>   /// \brief Different ways to break initializers.
>>   enum BreakConstructorInitializersStyle
>>   {
>>     /// Constructor()
>>     ///     : initializer1(),
>>     ///       initializer2()
>>     BCIS_BeforeColonAfterComma,
>>     /// Constructor()
>>     ///     : initializer1()
>>     ///     , initializer2()
>>     BCIS_BeforeColonAndComma,
>>     /// Constructor() :
>>     ///     initializer1(),
>>     ///     initializer2()
>>     BCIS_AfterColonAndComma
>>   };
>>
>>   /// \brief Breaking and alignment style for constructor initializers
>>   BreakConstructorInitializersStyle BreakConstructorInitializers;
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140914/c9b956b6/attachment.html>


More information about the cfe-dev mailing list