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: Sat, 15 May 2021 14:57:45 +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="23229"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, Lars Ingebrigtsen , 47468@debbugs.gnu.org To: Jianbin Kang Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 15 16:58:11 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 1lhvk2-0005vN-G2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 15 May 2021 16:58:10 +0200 Original-Received: from localhost ([::1]:36174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhvk1-0002lC-J2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 15 May 2021 10:58:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhvju-0002jl-Bd for bug-gnu-emacs@gnu.org; Sat, 15 May 2021 10:58:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37513) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lhvju-0005c9-3I for bug-gnu-emacs@gnu.org; Sat, 15 May 2021 10:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lhvju-0002tt-28 for bug-gnu-emacs@gnu.org; Sat, 15 May 2021 10:58:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 15 May 2021 14:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47468 X-GNU-PR-Package: emacs Original-Received: via spool by 47468-submit@debbugs.gnu.org id=B47468.162109067511136 (code B ref 47468); Sat, 15 May 2021 14:58:02 +0000 Original-Received: (at 47468) by debbugs.gnu.org; 15 May 2021 14:57:55 +0000 Original-Received: from localhost ([127.0.0.1]:49059 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhvjn-0002tY-Fq for submit@debbugs.gnu.org; Sat, 15 May 2021 10:57:55 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:49095 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1lhvjl-0002tK-DF for 47468@debbugs.gnu.org; Sat, 15 May 2021 10:57:53 -0400 Original-Received: (qmail 18552 invoked by uid 3782); 15 May 2021 14:57:46 -0000 Original-Received: from acm.muc.de (p4fe15ace.dip0.t-ipconnect.de [79.225.90.206]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 15 May 2021 16:57:46 +0200 Original-Received: (qmail 19699 invoked by uid 1000); 15 May 2021 14:57:45 -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:206608 Archived-At: 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).