GNU bug report logs - #63285
30.0.50; CC Mode: K&R argument declaration misdetection after parenthesized type

Previous Next

Package: emacs;

Reported by: Olivier Certner <ocert.dev <at> free.fr>

Date: Thu, 4 May 2023 21:55:02 UTC

Severity: normal

Tags: patch

Found in version 30.0.50

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 63285 in the body.
You can then email your comments to 63285 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#63285; Package emacs. (Thu, 04 May 2023 21:55:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Olivier Certner <ocert.dev <at> free.fr>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 04 May 2023 21:55:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Olivier Certner <ocert.dev <at> free.fr>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50;
 CC Mode: K&R argument declaration misdetection after parenthesized type
Date: Thu, 04 May 2023 23:54:49 +0200
[Message part 1 (text/plain, inline)]
Hello,

See attached 2-line reproducer.  E.g., type `C-c C-s' on the second line.

Fix to be attached as soon as the bug is created.

Regards.

-- 
Olivier Certner
[test.c (text/x-csrc, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63285; Package emacs. (Thu, 04 May 2023 21:58:02 GMT) Full text and rfc822 format available.

Message #8 received at 63285 <at> debbugs.gnu.org (full text, mbox):

From: Olivier Certner <ocert.dev <at> free.fr>
To: 63285 <at> debbugs.gnu.org
Subject: Re: bug#63285: Acknowledgement (30.0.50;
 CC Mode: K&R argument declaration misdetection after parenthesized type)
Date: Thu, 04 May 2023 23:57:14 +0200
[Message part 1 (text/plain, inline)]
Proposed fix.  Applies on master (b28d44d4226497c4b258).

-- 
Olivier Certner
[0001-CC-Mode-Fix-K-R-argument-declaration-misdetection-af.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63285; Package emacs. (Thu, 04 May 2023 22:15:01 GMT) Full text and rfc822 format available.

Message #11 received at 63285 <at> debbugs.gnu.org (full text, mbox):

From: Olivier Certner <ocert.dev <at> free.fr>
To: 63285 <at> debbugs.gnu.org
Subject: Re: 30.0.50;
 CC Mode: K&R argument declaration misdetection after parenthesized type
Date: Fri, 05 May 2023 00:14:48 +0200
[Message part 1 (text/plain, inline)]
Sorry, I had clobbered the "(+ (point) 1000)" part in the previous patch.

Please use this one instead.

-- 
Olivier Certner
[0001-CC-Mode-Fix-K-R-argument-declaration-misdetection-af.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63285; Package emacs. (Thu, 05 Oct 2023 20:44:01 GMT) Full text and rfc822 format available.

Message #14 received at 63285 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 63285 <at> debbugs.gnu.org, Olivier Certner <ocert.dev <at> free.fr>
Subject: Re: bug#63285: 30.0.50; CC Mode: K&R argument declaration
 misdetection after parenthesized type
Date: Thu, 5 Oct 2023 20:43:24 +0000
Olivier Certner <ocert.dev <at> free.fr> writes:

> Sorry, I had clobbered the "(+ (point) 1000)" part in the previous patch.
>
> Please use this one instead.

Alan, could you please take a look at the below patch?

Thanks in advance.

> From 0515de23d84a48c57b456c6730f826c5d783b965 Mon Sep 17 00:00:00 2001
> From: Olivier Certner <olce.emacs <at> certner.fr>
> Date: Wed, 3 May 2023 11:44:43 +0200
> Subject: [PATCH] CC Mode: Fix K&R argument declaration misdetection after
>  parenthesized type
>
> * lisp/progmodes/cc-engine.el (c-in-knr-argdecl): When trying to loop
> over candidate declarations (between the function declaration's
> identifier list's end and point) to check whether the names of their
> identifiers correspond with that of the identifier list, actually fail
> as soon as stumbling on something other than a declaration instead of
> silently succeeding, which causes some constructs to be erroneously
> recognized as K&R argument declarations.
>
> (Bug#63285)
> ---
>  lisp/progmodes/cc-engine.el | 29 ++++++++++++++++++-----------
>  1 file changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
> index 8b34daf03c2..27740b4903c 100644
> --- a/lisp/progmodes/cc-engine.el
> +++ b/lisp/progmodes/cc-engine.el
> @@ -12039,17 +12039,24 @@ c-in-knr-argdecl
>  		       ;; Each time around the following checks one
>  		       ;; declaration (which may contain several identifiers).
>  		       (while (and
> -			       (consp (setq decl-or-cast
> -					    (c-forward-decl-or-cast-1
> -					     after-prec-token
> -					     nil ; Or 'arglist ???
> -					     nil)))
> -			       (memq (char-after) '(?\; ?\,))
> -			       (goto-char (car decl-or-cast))
> -			       (save-excursion
> -				 (setq semi-position+1
> -				       (c-syntactic-re-search-forward
> -					";" (+ (point) 1000) t)))
> +			       (or
> +				(and
> +				 (consp (setq decl-or-cast
> +					      (c-forward-decl-or-cast-1
> +					       after-prec-token
> +					       nil ; Or 'arglist ???
> +					       nil)))
> +				 (memq (char-after) '(?\; ?\,))
> +				 (goto-char (car decl-or-cast))
> +				 (save-excursion
> +				   (setq semi-position+1
> +					 (1+ (or
> +					      (c-syntactic-re-search-forward
> +					       ";" (+ (point) 1000) t)
> +					      (1- (point-max)))))))
> +				;; Can't parse declarations correctly,
> +				;; bail out.
> +				(throw 'knr nil))
>  			       (c-do-declarators
>  				semi-position+1 t nil nil
>  				(lambda (id-start id-end _next _not-top
> --
> 2.39.2




Added tag(s) patch. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 05 Oct 2023 20:45:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63285; Package emacs. (Fri, 06 Oct 2023 09:11:02 GMT) Full text and rfc822 format available.

Message #19 received at 63285 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 63285 <at> debbugs.gnu.org, Olivier Certner <ocert.dev <at> free.fr>
Subject: Re: bug#63285: 30.0.50; CC Mode: K&R argument declaration
 misdetection after parenthesized type
Date: Fri, 6 Oct 2023 09:09:57 +0000
Hello, Stefan.

On Thu, Oct 05, 2023 at 20:43:24 +0000, Stefan Kangas wrote:
> Olivier Certner <ocert.dev <at> free.fr> writes:

> > Sorry, I had clobbered the "(+ (point) 1000)" part in the previous patch.
> >
> > Please use this one instead.

> Alan, could you please take a look at the below patch?

I'm looking at the bug, now.  I'll get back again once I think I
understand it.  ;-)

> Thanks in advance.

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63285; Package emacs. (Fri, 06 Oct 2023 13:19:02 GMT) Full text and rfc822 format available.

Message #22 received at 63285 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Olivier Certner <ocert.dev <at> free.fr>, Stefan Kangas <stefankangas <at> gmail.com>
Cc: acm <at> muc.de, 63285 <at> debbugs.gnu.org
Subject: Re: bug#63285: 30.0.50; CC Mode: K&R argument declaration
 misdetection after parenthesized type
Date: Fri, 6 Oct 2023 13:18:01 +0000
Hello, Olivier and Stefan.

On Thu, Oct 05, 2023 at 20:43:24 +0000, Stefan Kangas wrote:
> Olivier Certner <ocert.dev <at> free.fr> writes:

> > Sorry, I had clobbered the "(+ (point) 1000)" part in the previous patch.
> >
> > Please use this one instead.

Olivier, thanks for taking the trouble to submit this bug report.  Sorry
it's taken me so long to getting around to looking at it.

> Alan, could you please take a look at the below patch?

> Thanks in advance.

> > From 0515de23d84a48c57b456c6730f826c5d783b965 Mon Sep 17 00:00:00 2001
> > From: Olivier Certner <olce.emacs <at> certner.fr>
> > Date: Wed, 3 May 2023 11:44:43 +0200
> > Subject: [PATCH] CC Mode: Fix K&R argument declaration misdetection after
> >  parenthesized type
> >
> > * lisp/progmodes/cc-engine.el (c-in-knr-argdecl): When trying to loop
> > over candidate declarations (between the function declaration's
> > identifier list's end and point) to check whether the names of their
> > identifiers correspond with that of the identifier list, actually fail
> > as soon as stumbling on something other than a declaration instead of
> > silently succeeding, which causes some constructs to be erroneously
> > recognized as K&R argument declarations.

I don't think this would be quite the right way to go.  It would be too
rigorous in rejecting partially written K&R constructs which might cause
them to be excessively reindented as commas and or semicolons get typed.

It seems that (throw 'knr nil) when the c-forward-decl-or-cast-1 form
fails is sufficient to prevent the wrong recognition of your test file's
line 2 as a K&R declaration.  Please feel free to try out my (simpler)
patch below on your real C code.

Also, I propose adopting your 2-line test file, reindented, as a new
test in the CC Mode test suite.  Please let me know if you'd prefer that
not to happen.

> > (Bug#63285)
> > ---
> >  lisp/progmodes/cc-engine.el | 29 ++++++++++++++++++-----------
> >  1 file changed, 18 insertions(+), 11 deletions(-)
> >
> > diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
> > index 8b34daf03c2..27740b4903c 100644
> > --- a/lisp/progmodes/cc-engine.el
> > +++ b/lisp/progmodes/cc-engine.el
> > @@ -12039,17 +12039,24 @@ c-in-knr-argdecl
> >  		       ;; Each time around the following checks one
> >  		       ;; declaration (which may contain several identifiers).
> >  		       (while (and
> > -			       (consp (setq decl-or-cast
> > -					    (c-forward-decl-or-cast-1
> > -					     after-prec-token
> > -					     nil ; Or 'arglist ???
> > -					     nil)))
> > -			       (memq (char-after) '(?\; ?\,))
> > -			       (goto-char (car decl-or-cast))
> > -			       (save-excursion
> > -				 (setq semi-position+1
> > -				       (c-syntactic-re-search-forward
> > -					";" (+ (point) 1000) t)))
> > +			       (or
> > +				(and
> > +				 (consp (setq decl-or-cast
> > +					      (c-forward-decl-or-cast-1
> > +					       after-prec-token
> > +					       nil ; Or 'arglist ???
> > +					       nil)))
> > +				 (memq (char-after) '(?\; ?\,))
> > +				 (goto-char (car decl-or-cast))
> > +				 (save-excursion
> > +				   (setq semi-position+1
> > +					 (1+ (or
> > +					      (c-syntactic-re-search-forward
> > +					       ";" (+ (point) 1000) t)
> > +					      (1- (point-max)))))))
> > +				;; Can't parse declarations correctly,
> > +				;; bail out.
> > +				(throw 'knr nil))
> >  			       (c-do-declarators
> >  				semi-position+1 t nil nil
> >  				(lambda (id-start id-end _next _not-top
> > --
> > 2.39.2

Here's my amended patch:



diff -r b680bbba3141 cc-engine.el
--- a/cc-engine.el	Fri Sep 29 11:15:58 2023 +0000
+++ b/cc-engine.el	Fri Oct 06 11:22:31 2023 +0000
@@ -12285,11 +12285,14 @@
 		       ;; Each time around the following checks one
 		       ;; declaration (which may contain several identifiers).
 		       (while (and
-			       (consp (setq decl-or-cast
-					    (c-forward-decl-or-cast-1
-					     after-prec-token
-					     nil ; Or 'arglist ???
-					     nil)))
+			       (not (eq (char-after) ?{))
+			       (or
+				(consp (setq decl-or-cast
+					     (c-forward-decl-or-cast-1
+					      after-prec-token
+					      nil ; Or 'arglist ???
+					      nil)))
+				(throw 'knr nil))
 			       (memq (char-after) '(?\; ?\,))
 			       (goto-char (car decl-or-cast))
 			       (save-excursion


-- 
Alan Mackenzie (Nuremberg, Germany).




Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Fri, 13 Oct 2023 14:40:02 GMT) Full text and rfc822 format available.

Notification sent to Olivier Certner <ocert.dev <at> free.fr>:
bug acknowledged by developer. (Fri, 13 Oct 2023 14:40:02 GMT) Full text and rfc822 format available.

Message #27 received at 63285-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: acm <at> muc.de, 63285-done <at> debbugs.gnu.org
Subject: Re: bug#63285: 30.0.50; CC Mode: K&R argument declaration
 misdetection after parenthesized type
Date: Fri, 13 Oct 2023 14:38:56 +0000
Hello, Stefan.

I've committed a patch which fixes this bug.  I'm now closing it.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63285; Package emacs. (Fri, 13 Oct 2023 15:06:02 GMT) Full text and rfc822 format available.

Message #30 received at 63285-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 63285-done <at> debbugs.gnu.org
Subject: Re: bug#63285: 30.0.50; CC Mode: K&R argument declaration
 misdetection after parenthesized type
Date: Fri, 13 Oct 2023 15:04:37 +0000
Alan Mackenzie <acm <at> muc.de> writes:

> I've committed a patch which fixes this bug.  I'm now closing it.

Thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 11 Nov 2023 12:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 167 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.