[cfe-dev] [llvm-dev] clang-format behaviour for braced lists indent

martin lampacher via cfe-dev cfe-dev at lists.llvm.org
Tue Sep 10 04:15:07 PDT 2019


Hi Owen,

looking good, thanks a lot! Will this patch be part of the 9.0 release?

Cheers.M

> On 10 Sep 2019, at 12:19, Owen Pan <owenpiano at gmail.com> wrote:
> 
> Hi Martin,
> 
> Please see below:
> 
> build$ cp ATT11905.clang-format .clang-format
> build$ bin/clang-format SomeUnit.c > SomeUnit.c.c-f
> build$ diff SomeUnit.c SomeUnit.c.c-f
> 30,35c30,36
> < static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
> <                                 CDDDP83848_BMSR_REGISTER,
> <                                 CDDDP83848_PHYIDR1_REGISTER,
> <                                 CDDDP83848_PHYIDR2_REGISTER,
> <                                 CDDDP83848_PHYSTS_REGISTER,
> <                                 CDDDP83848_RBR_REGISTER};
> ---
> > static uint8 CddDp83848Reg[] = {
> >     CDDDP83848_BMCR_REGISTER,
> >     CDDDP83848_BMSR_REGISTER,
> >     CDDDP83848_PHYIDR1_REGISTER,
> >     CDDDP83848_PHYIDR2_REGISTER,
> >     CDDDP83848_PHYSTS_REGISTER,
> >     CDDDP83848_RBR_REGISTER};
> build$ 
> 
> I will create a patch and commit the fix in a few days.
> 
> Regards,
> 
> Owen
> 
> On Tue, Sep 10, 2019 at 2:08 AM martin lampacher <lmapii at googlemail.com <mailto:lmapii at googlemail.com>> wrote:
> Hi,
> 
> Shoaib was so nice to forward this to the correct list. Yes, that's what I'd need. Deafult or LLVM style would generate this but only because of the low ColumnLimit, which is 120 (and in future even 150) for my case. At least that's what I've figured when comparing against the LLVM style dump.
> 
> I've attached the clang-format file as well as the source file - maybe the files got lost while forwarding.
> 
> Cheers, Martin
> 
> 
>> On 10 Sep 2019, at 10:41, Owen Pan <owenpiano at gmail.com <mailto:owenpiano at gmail.com>> wrote:
>> 
>> Hi Shoaib,
>> 
>> Is this what you need? Can you send the .clang-format file you used?
>> 
>> build$ cat BracedList.cpp
>> static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
>>                                 CDDDP83848_BMSR_REGISTER,
>>                                 CDDDP83848_PHYIDR1_REGISTER,
>>                                 CDDDP83848_PHYIDR2_REGISTER,
>>                                 CDDDP83848_PHYSTS_REGISTER,
>>                                 CDDDP83848_RBR_REGISTER};
>> build$ bin/clang-format BracedList.cpp
>> static uint8 CddDp83848Reg[] = {
>>     CDDDP83848_BMCR_REGISTER,
>>     CDDDP83848_BMSR_REGISTER,
>>     CDDDP83848_PHYIDR1_REGISTER,
>>     CDDDP83848_PHYIDR2_REGISTER,
>>     CDDDP83848_PHYSTS_REGISTER,
>>     CDDDP83848_RBR_REGISTER};
>> build$ 
>> 
>> Regards,
>> 
>> Owen
>> 
>> On Mon, Sep 9, 2019 at 8:23 AM Shoaib Meenai via cfe-dev <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
>> (forwarding this to cfe-dev and BCC'ing llvm-dev, since cfe-dev is a better place for clang-format queries)
>> 
>>  
>> 
>> From: llvm-dev <llvm-dev-bounces at lists.llvm.org <mailto:llvm-dev-bounces at lists.llvm.org>> on behalf of martin lampacher via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>>
>> Reply-To: martin lampacher <lmapii at googlemail.com <mailto:lmapii at googlemail.com>>
>> Date: Monday, September 9, 2019 at 12:04 AM
>> To: LLVM Development List <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>>
>> Subject: [llvm-dev] clang-format behaviour for braced lists indent
>> 
>>  
>> 
>> Hello,
>> 
>>  
>> 
>> I've introduced clang-format (current version 8.0) to enforce some company coding guideline but I am struggling with list initializers.
>> 
>>  
>> 
>> The formatter works nicely with function declarations and function calls and aligns arguments on break like that:
>> 
>>  
>> 
>>  
>> 
>> static void someUnitInternalFunction(
>> 
>>  
>> 
>>     const uint32 someParameter,
>> 
>>  
>> 
>>     uint32 *somePointer,
>> 
>>  
>> 
>>     uint32 normalParameter,
>> 
>>  
>> 
>>     uint8 anotherParameterLong);
>> 
>>  
>> 
>>  
>> 
>> 
>> 
>> 
>> uint32 SomeUnitWithSomeVeryLongFunctionName(
>> 
>>  
>> 
>>     uint32 parameterOne,
>> 
>>  
>> 
>>     uint32 parameterTwo,
>> 
>>  
>> 
>>     uint32 parameterThree,
>> 
>>  
>> 
>>     uint32 parameterFour)
>> 
>>  
>> 
>> {
>> 
>>  
>> 
>>     someUnitInternalFunction(
>> 
>>  
>> 
>>         someInternalVariableWithSomeVeryLongName,
>> 
>>  
>> 
>>         &yetAnotherInternalVariableLongNameStyle,
>> 
>>  
>> 
>>         nowThisNameIsShorter,
>> 
>>  
>> 
>>         nowThisNameIsShorter);
>> 
>>  
>> 
>> }
>> 
>>  
>> 
>>  
>> 
>>  
>> 
>>  
>> 
>> This matches the configured continuation indent width. For lists, however, the indent does not match what I've expected: A list that exceeds the configured margin is formatted as following (I'm using Cpp11BracedListStyle: true):
>> 
>>  
>> 
>>  
>> 
>> static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
>> 
>>  
>> 
>>                                 CDDDP83848_BMSR_REGISTER,
>> 
>>  
>> 
>>                                 CDDDP83848_PHYIDR1_REGISTER,
>> 
>>  
>> 
>>                                 CDDDP83848_PHYIDR2_REGISTER,
>> 
>>  
>> 
>>                                 CDDDP83848_PHYSTS_REGISTER,
>> 
>>  
>> 
>>                                 CDDDP83848_RBR_REGISTER};
>> 
>>  
>> 
>>  
>> 
>> Whereas I'd expect it the following style:
>> 
>>  
>> 
>>  
>> 
>> static uint8 CddDp83848Reg[] = {
>> 
>>  
>> 
>>     CDDDP83848_BMCR_REGISTER,
>> 
>>  
>> 
>>     CDDDP83848_BMSR_REGISTER,
>> 
>>  
>> 
>>     CDDDP83848_PHYIDR1_REGISTER,
>> 
>>  
>> 
>>     CDDDP83848_PHYIDR2_REGISTER,
>> 
>>  
>> 
>>     CDDDP83848_PHYSTS_REGISTER,
>> 
>>  
>> 
>>     CDDDP83848_RBR_REGISTER};
>> 
>>  
>> 
>>  
>> 
>> According to the documentation
>> 
>>  
>> 
>> Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.
>> 
>>  
>> 
>> And I have the following setting: ContinuationIndentWidth: 4. As you can see the function call is formatted nicely whereas the list initializer isn't, according to the documentation the formatting should be the same.
>> 
>>  
>> 
>> Can someone please help me out here? I've checked several settings and can't make clang-format indent initializers according to the (admittedly a bit special) style.
>> 
>>  
>> 
>> Thanks and BR,
>> 
>> Martin
>> 
>>  
>> 
>> Attached demo file and clang-format settings
>> 
>>  
>> 
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190910/72e722ba/attachment.html>


More information about the cfe-dev mailing list