From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs 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 Message-ID: <20171004181552.GA15562@ACM> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1507141571 28673 195.159.176.226 (4 Oct 2017 18:26:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 4 Oct 2017 18:26:11 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: John Wiegley , 28623@debbugs.gnu.org To: Tadeus Prastowo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 04 20:26:07 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzoMw-0006qA-4a for geb-bug-gnu-emacs@m.gmane.org; Wed, 04 Oct 2017 20:26:06 +0200 Original-Received: from localhost ([::1]:36383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzoN3-0004eK-IL for geb-bug-gnu-emacs@m.gmane.org; Wed, 04 Oct 2017 14:26:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzoMx-0004e8-FL for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2017 14:26:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzoMs-0004xT-Ci for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2017 14:26:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40506) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dzoMs-0004wp-3K; Wed, 04 Oct 2017 14:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dzoMr-0002lI-SF; Wed, 04 Oct 2017 14:26:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Wed, 04 Oct 2017 18:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28623 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 28623-submit@debbugs.gnu.org id=B28623.150714151610562 (code B ref 28623); Wed, 04 Oct 2017 18:26:01 +0000 Original-Received: (at 28623) by debbugs.gnu.org; 4 Oct 2017 18:25:16 +0000 Original-Received: from localhost ([127.0.0.1]:49187 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzoM6-0002kD-Kk for submit@debbugs.gnu.org; Wed, 04 Oct 2017 14:25:16 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:29835 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1dzoM3-0002k4-Tk for 28623@debbugs.gnu.org; Wed, 04 Oct 2017 14:25:12 -0400 Original-Received: (qmail 25920 invoked by uid 3782); 4 Oct 2017 18:25:06 -0000 Original-Received: from acm.muc.de (p548C6F55.dip0.t-ipconnect.de [84.140.111.85]) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 04 Oct 2017 20:25:06 +0200 Original-Received: (qmail 15600 invoked by uid 1000); 4 Oct 2017 18:15:53 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:137912 Archived-At: 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 > #include > static std::vector> > fn(std::vector> data) { > return { > {1, 2, 3}, > {4, 5, 6}, > {7, 8, 9}, > }; > } > static std::vector> > fn(unsigned n, std::vector> 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).