GNU bug report logs - #27130
c-mode indentation mistreats structs in function arguments

Previous Next

Packages: emacs, cc-mode;

Reported by: Sam Pagenkopf <ssaammp <at> gmail.com>

Date: Mon, 29 May 2017 16:01:02 UTC

Severity: normal

Tags: confirmed

To reply to this bug, email your comments to 27130 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#27130; Package emacs. (Mon, 29 May 2017 16:01:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sam Pagenkopf <ssaammp <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 29 May 2017 16:01:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sam Pagenkopf <ssaammp <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: c-mode indentation mistreats structs in function arguments
Date: Mon, 29 May 2017 08:33:35 -0500
[Message part 1 (text/plain, inline)]
In emacs 25.2.1.

Relevant code:

    draw_add(&battle.draw, (Drawn){
            .kind = DRAW_RECT,
                .size = {40,24},
                .pos.border = {
                .align = {ALIGN_LEFT, ALIGN_TOP},
                .dist = 3
            }
        }
        );

My guess is that it's reading (Drawn){...} as a statement, and the , as
the (,) C operator.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#27130; Package emacs,cc-mode. (Mon, 30 Nov 2020 11:13:02 GMT) Full text and rfc822 format available.

Message #8 received at 27130 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Sam Pagenkopf <ssaammp <at> gmail.com>
Cc: 27130 <at> debbugs.gnu.org, Alan Mackenzie <acm <at> muc.de>
Subject: Re: bug#27130: c-mode indentation mistreats structs in function
 arguments
Date: Mon, 30 Nov 2020 12:11:56 +0100
Sam Pagenkopf <ssaammp <at> gmail.com> writes:

> In emacs 25.2.1.
>
> Relevant code:
>
>     draw_add(&battle.draw, (Drawn){
>             .kind = DRAW_RECT,
>                 .size = {40,24},
>                 .pos.border = {
>                 .align = {ALIGN_LEFT, ALIGN_TOP},
>                 .dist = 3
>             }
>         }
>         );
>
> My guess is that it's reading (Drawn){...} as a statement, and the , as
> the (,) C operator.

I'm not sure how this should be indented (as I didn't even know that
that was valid C).  But that does look wrong, in any case.  (I've
confirmed that it indents it the same way in Emacs 28.)

Alan?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) confirmed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 30 Nov 2020 11:13:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#27130; Package emacs,cc-mode. (Mon, 30 Nov 2020 17:05:02 GMT) Full text and rfc822 format available.

Message #13 received at 27130 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Sam Pagenkopf <ssaammp <at> gmail.com>, 27130 <at> debbugs.gnu.org, acm <at> muc.de
Subject: Re: bug#27130: c-mode indentation mistreats structs in function
 arguments
Date: Mon, 30 Nov 2020 17:04:34 +0000
Hello, Lars.

On Mon, Nov 30, 2020 at 12:11:56 +0100, Lars Ingebrigtsen wrote:
> Sam Pagenkopf <ssaammp <at> gmail.com> writes:

> > In emacs 25.2.1.

> > Relevant code:

> >     draw_add(&battle.draw, (Drawn){
> >             .kind = DRAW_RECT,
> >                 .size = {40,24},
> >                 .pos.border = {
> >                 .align = {ALIGN_LEFT, ALIGN_TOP},
> >                 .dist = 3
> >             }
> >         }
> >         );

> > My guess is that it's reading (Drawn){...} as a statement, and the , as
> > the (,) C operator.

> I'm not sure how this should be indented (as I didn't even know that
> that was valid C).  But that does look wrong, in any case.  (I've
> confirmed that it indents it the same way in Emacs 28.)

> Alan?

That's strange.  In my Emacs 28 copy, I get this indentation:

    int main ()
    {
        draw_add(&battle.draw, (Drawn){
                .kind = DRAW_RECT,
                .size = {40,24},
                .pos.border = {
                    .align = {ALIGN_LEFT, ALIGN_TOP},
                    .dist = 3
                }
            }
            );
    }

, which apart from the closing parenthesis being indented too far, looks
basically OK.  Possibly, one might want the .kind line indented one space
further (it is indented 2 * c-basic-offset from the draw_add on the
previous line).  C-c C-s on that line gives the following analysis:

    ((arglist-cont-nonempty 19 27) (brace-list-intro 19))

.  C-c C-s on the following line should give

    ((brace-list-entry 63))

, where 63 is the position of the . in .kind.  This is correct.  In fact,
something in this area was corrected in the last three or four years, 

The closing paren is lined up by c-align-arglist-close-under-paren, which
contains a bit of DWIMery which misfires here, causing the ) to be
indented c-basic-offset from the first character on the line opening the
construct (here the draw_add line).  This DWIMery has also recently
misfired on a C++ file, so I think I'll have to modernise
c-align-arglist-close-under-paren to be more discerning.

> -- 
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#27130; Package emacs,cc-mode. (Wed, 02 Dec 2020 09:56:01 GMT) Full text and rfc822 format available.

Message #16 received at 27130 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Sam Pagenkopf <ssaammp <at> gmail.com>, 27130 <at> debbugs.gnu.org
Subject: Re: bug#27130: c-mode indentation mistreats structs in function
 arguments
Date: Wed, 02 Dec 2020 10:55:26 +0100
Alan Mackenzie <acm <at> muc.de> writes:

> Hello, Lars.
>
> On Mon, Nov 30, 2020 at 12:11:56 +0100, Lars Ingebrigtsen wrote:
>> Sam Pagenkopf <ssaammp <at> gmail.com> writes:
>
>> > In emacs 25.2.1.
>
>> > Relevant code:
>
>> >     draw_add(&battle.draw, (Drawn){
>> >             .kind = DRAW_RECT,
>> >                 .size = {40,24},
>> >                 .pos.border = {
>> >                 .align = {ALIGN_LEFT, ALIGN_TOP},
>> >                 .dist = 3
>> >             }
>> >         }
>> >         );
>
>> > My guess is that it's reading (Drawn){...} as a statement, and the , as
>> > the (,) C operator.
>
>> I'm not sure how this should be indented (as I didn't even know that
>> that was valid C).  But that does look wrong, in any case.  (I've
>> confirmed that it indents it the same way in Emacs 28.)
>
>> Alan?
>
> That's strange.  In my Emacs 28 copy, I get this indentation:
>
>     int main ()
>     {
>         draw_add(&battle.draw, (Drawn){
>                 .kind = DRAW_RECT,
>                 .size = {40,24},
>                 .pos.border = {
>                     .align = {ALIGN_LEFT, ALIGN_TOP},
>                     .dist = 3
>                 }
>             }
>             );
>     }
>
> , which apart from the closing parenthesis being indented too far, looks
> basically OK.

I was thinking the next-to-last } was in a somewhat odd place (the one
that closes the Drawn), but on the other hand I don't really know where
else it should be.  On the third hand...

int main ()
{
  draw_add(&battle.draw, (Drawn)
           {
             .kind = DRAW_RECT,
             .size = {40,24},
             .pos.border = {
               .align = {ALIGN_LEFT, ALIGN_TOP},
               .dist = 3
             }
           }
           );
}

Now the end brace looks correct to me.  So perhaps it should be indented
the same way in the original case?  That is:

int main ()
{
  draw_add(&battle.draw, (Drawn) {
             .kind = DRAW_RECT,
             .size = {40,24},
             .pos.border = {
               .align = {ALIGN_LEFT, ALIGN_TOP},
               .dist = 3
             }
           }
           );
}

I'm talking about the braces only -- as you point out, the end
parenthesis is a different matter.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




This bug report was last modified 4 years and 195 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.