From: Alan Mackenzie <acm@muc.de>
To: Jianbin Kang <kjbmail@gmail.com>
Cc: acm@muc.de, Lars Ingebrigtsen <larsi@gnus.org>,
47468-done@debbugs.gnu.org
Subject: bug#47468: 27.1; cc-mode: Got incorrect indentaton for C++ lambda function.
Date: Sun, 15 Aug 2021 19:51:09 +0000 [thread overview]
Message-ID: <YRlwLfcZjcochyb8@ACM> (raw)
In-Reply-To: <YJ/haYlwMzXdFrhI@ACM>
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 <stdio.h>
> > #include <functional>
> > struct PP {
> > const char * name;
> > };
> > static void print(const char *name, std::function<void(const char *)> 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).
next prev parent reply other threads:[~2021-08-15 19:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-29 12:47 bug#47468: 27.1; cc-mode: Got incorrect indentaton for C++ lambda function Jianbin Kang
2021-05-12 21:57 ` Lars Ingebrigtsen
2021-05-15 14:57 ` Alan Mackenzie
2021-08-15 19:51 ` Alan Mackenzie [this message]
2021-05-19 20:49 ` Vladimir Lichevsky
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=YRlwLfcZjcochyb8@ACM \
--to=acm@muc.de \
--cc=47468-done@debbugs.gnu.org \
--cc=kjbmail@gmail.com \
--cc=larsi@gnus.org \
/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).