From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#47468: 27.1; cc-mode: Got incorrect indentaton for C++ lambda function. Date: Sun, 15 Aug 2021 19:51:09 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13881"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, Lars Ingebrigtsen , 47468-done@debbugs.gnu.org To: Jianbin Kang Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 15 21:53:44 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mFMCU-0003Ph-7S for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Aug 2021 21:53:42 +0200 Original-Received: from localhost ([::1]:41718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mFMCS-0006FD-So for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Aug 2021 15:53:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFMAr-0004uI-Vs for bug-gnu-emacs@gnu.org; Sun, 15 Aug 2021 15:52:01 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36258) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mFMAr-0005BR-P9 for bug-gnu-emacs@gnu.org; Sun, 15 Aug 2021 15:52:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mFMAr-00050n-Kx for bug-gnu-emacs@gnu.org; Sun, 15 Aug 2021 15:52:01 -0400 Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Aug 2021 19:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 47468 X-GNU-PR-Package: emacs Mail-Followup-To: 47468@debbugs.gnu.org, acm@muc.de, kjbmail@gmail.com Original-Received: via spool by 47468-done@debbugs.gnu.org id=D47468.162905708019213 (code D ref 47468); Sun, 15 Aug 2021 19:52:01 +0000 Original-Received: (at 47468-done) by debbugs.gnu.org; 15 Aug 2021 19:51:20 +0000 Original-Received: from localhost ([127.0.0.1]:47804 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mFMAC-0004zp-54 for submit@debbugs.gnu.org; Sun, 15 Aug 2021 15:51:20 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:58029 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1mFMA9-0004zb-6L for 47468-done@debbugs.gnu.org; Sun, 15 Aug 2021 15:51:19 -0400 Original-Received: (qmail 2112 invoked by uid 3782); 15 Aug 2021 19:51:10 -0000 Original-Received: from acm.muc.de (p2e5d53a5.dip0.t-ipconnect.de [46.93.83.165]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 15 Aug 2021 21:51:09 +0200 Original-Received: (qmail 10644 invoked by uid 1000); 15 Aug 2021 19:51:09 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:211944 Archived-At: Hello, Jianbin and Lars. Some while has passed since the bug was opened, and since the patch I suggested seems to fix it, I am now closing this bug. -- Alan Mackenzie (Nuremberg, Germany). On Sat, May 15, 2021 at 14:57:45 +0000, Alan Mackenzie wrote: > Hello, Jianbin. > Thank you indeed for taking the trouble to report this bug, and thank > you even more for cutting the test case down to a concise, easy to work > with file. > On Mon, Mar 29, 2021 at 20:47:52 +0800, Jianbin Kang wrote: > > The c++ file to reproduce it: > > ```c++ > > #include > > #include > > struct PP { > > const char * name; > > }; > > static void print(const char *name, std::function f) > > { > > f(name); > > } > > int main(int argc, char *argv[]) > > { > > PP A = { "Jim" }; > > PP *a = &A; > > print(A.name, [](const char *name) { > > printf("%s\n", name); // Syntactic ((inlambda) ... > > }); > > print(a->name, [=](const char *name) { > > printf("%s\n", name); // Syntactic((arglist-cont-nonempty > > ... > > }); > > return 0; > > } > > ``` > > If I put cursor in lambda body of first print call, and run > > 'c-show-syntactic-information', it shows 'Syntactic analysis: ((inlambda) > > (defun-block-intro 258))', which is correct and I get good indentation. > > But in second print call, I get 'Syntactic analysis: > > ((arglist-cont-nonempty 337 342) (statement-block-intro 337))' and the > > indentation is bad. > Yes. What is happening is that CC Mode is falsely recognising the -> in > a->name as the trailing return type of the lambda expression. > I think the following patch should fix it. Could I ask you, please, to > apply this patch to ..../emacs/lisp/progmodes/cc-engine.el, byte-compile > the file, and try it out on your real C++ source code. In the unlikely > event you want help with the patching or byte-compilation, feel free to > send me private email. After this, please either confirm to us that the > problem is fixed, or tell us what is still not working. Thanks! > diff -r 92a4592886a1 cc-engine.el > --- a/cc-engine.el Sun Apr 25 17:26:38 2021 +0000 > +++ b/cc-engine.el Sat May 15 14:51:56 2021 +0000 > @@ -12269,7 +12269,7 @@ > (save-excursion > (while > (progn > - (c-syntactic-skip-backward "^;=}>" closest-lim t) > + (c-syntactic-skip-backward "^;=,}>" closest-lim t) > (and (eq (char-before) ?>) > (c-backward-token-2) > (not (looking-at c-haskell-op-re))))) > > My emacs version is 27.1. I can reproduce the problem in both Linux and > > Windows with 'emacs -Q'. > -- > Alan Mackenzie (Nuremberg, Germany).