unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Tadeus Prastowo <tadeus.prastowo@unitn.it>
Cc: John Wiegley <jwiegley@gmail.com>, 28623@debbugs.gnu.org
Subject: bug#28623: 27.0.50; lisp/progmodes/cc-engine.el incorrect indentation of C++14 curly-brace initializer list
Date: Wed, 4 Oct 2017 18:15:53 +0000	[thread overview]
Message-ID: <20171004181552.GA15562@ACM> (raw)
In-Reply-To: <CAN-HRFaiSooECSd0Z5GeiQf2z=GzjTEM4yviroHZfT6=q86yVQ@mail.gmail.com>

Hello, Tadeus.

On Wed, Sep 27, 2017 at 19:49:57 +0200, Tadeus Prastowo wrote:
> The following C++14 source code, which is also attached as `mwe.cpp',
> shows the indentation problem:

> --8<------------------------------
> #include <vector>
> #include <iostream>

> static std::vector<std::vector<unsigned>>
> fn(std::vector<std::vector<unsigned>> data) {
>   return {
>           {1, 2, 3},
>           {4, 5, 6},
>           {7, 8, 9},
>   };
> }

> static std::vector<std::vector<unsigned>>
> fn(unsigned n, std::vector<std::vector<unsigned>> data) {
>   return {
>           {n + 1, n + 2, n + 3},
>           {n + 4, n + 5, n + 6},
>           {n + 7, n + 8, n + 9},
>   };
> }

> int main() {
>   /* Expected indentation */
>   fn({
>       {1, 2, 3},
>       {3, 4, 5},
>       {6, 7, 8},
>     });
>   for (const auto &v : fn({
>                            {3, 4, 5},
>                            {6, 7, 8},
>                            {9, 10, 11},
>       })) {
>     for (const auto &a : v) {
>       std::cout << a << '\n';
>     }
>   }
>   /* End: Expected indentation */

>   /* Problem */
>   fn(20, {
>       {1, 2, 3},
>         {3, 4, 5},
>           {6, 7, 8},
>             });
>   for (const auto &v : fn(20, {
>         {3, 4, 5},
>           {6, 7, 8},
>             {9, 10, 11},
>               })) {
>     for (const auto &a : v) {
>       std::cout << a << '\n';
>     }
>   }
>   /* End: Problem */
> }
> --8<------------------------------

Yes.

> To fix the problem, I make the following patch:
> --8<------------------------------
> diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
> index 05b391a..077e9c9 100644
> --- a/lisp/progmodes/cc-engine.el
> +++ b/lisp/progmodes/cc-engine.el
> @@ -10387,6 +10387,7 @@ comment at the start of cc-engine.el for more info."
>                (eq (char-after) ?\())
>           (setq braceassignp 'c++-noassign))
>          ((looking-at c-pre-id-bracelist-key))
> +        ((looking-at ",\\s *"))
>          ((looking-at c-return-key))
>          ((and (looking-at c-symbol-start)
>                (not (looking-at c-keywords-regexp)))
> @@ -10398,6 +10399,7 @@ comment at the start of cc-engine.el for more info."
>             (and (c-go-up-list-backward nil lim) ; FIXME!!! Check
> `lim' 2016-07-12.
>              (eq (char-after) ?\()))
>            ((looking-at c-pre-id-bracelist-key))
> +          ((looking-at ",\\s *"))
>            ((looking-at c-return-key))
>            (t (setq after-type-id-pos (point))
>               nil))))
> --8<------------------------------

> Any better suggestion as to how to fix the problem?

Hey, I just love it when people diagnose and fix their own bugs,
particularly in some of the more involved bits of CC Mode.  :-)

Just one tiny, tiny, nitpick.  in (looking-at ",\\s *"), isn't the "any
amount of space" bit redundant, since we don't use match-end to get the
precise position?  In fact, I'm tending towards the simpler (eq
(char-after) ?,).

But, as I say, that's a tiny point in a great piece of debugging.  I
will commit this (to the Emacs-26 branch of savannah) soon (from where
it will find its way to the master branch due to some public spirited
person who arranges these things).

Many thanks!

> Thanks.

> In GNU Emacs 27.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
>  of 2017-09-27 built on lgw01-amd64-052
> Windowing system distributor 'The X.Org Foundation', version 11.0.11804000
> System Description:    Ubuntu 16.04.3 LTS

[ .... ]

> Major mode: C++//l

[ .... ]

> --
> Best regards,
> Tadeus

-- 
Alan Mackenzie (Nuremberg, Germany).





  parent reply	other threads:[~2017-10-04 18:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27 17:49 bug#28623: 27.0.50; lisp/progmodes/cc-engine.el incorrect indentation of C++14 curly-brace initializer list Tadeus Prastowo
2017-09-27 19:31 ` John Wiegley
2017-10-04 18:15 ` Alan Mackenzie [this message]
2017-10-06  2:59   ` Tadeus Prastowo
2017-10-11 20:32     ` Alan Mackenzie
2017-10-12 11:38       ` Tadeus Prastowo
2017-11-04 19:56         ` Alan Mackenzie
2017-11-06 22:46           ` Tadeus Prastowo
2017-11-08 19:23             ` Alan Mackenzie
     [not found]             ` <20171108192358.GA4582@ACM>
2017-11-09  9:27               ` Tadeus Prastowo
2017-11-09 18:53                 ` Alan Mackenzie
     [not found]                 ` <20171109185354.GA15085@ACM>
2017-11-10 12:07                   ` Tadeus Prastowo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171004181552.GA15562@ACM \
    --to=acm@muc.de \
    --cc=28623@debbugs.gnu.org \
    --cc=jwiegley@gmail.com \
    --cc=tadeus.prastowo@unitn.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).