unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Olivier Certner <ocert.dev@free.fr>
To: 63285@debbugs.gnu.org
Subject: bug#63285: 30.0.50; CC Mode: K&R argument declaration misdetection after parenthesized type
Date: Fri, 05 May 2023 00:14:48 +0200	[thread overview]
Message-ID: <2329887.yEB1Cff6dg@ravel> (raw)
In-Reply-To: <51034426.rt4x2z8vUf@ravel>

[-- Attachment #1: Type: text/plain, Size: 124 bytes --]

Sorry, I had clobbered the "(+ (point) 1000)" part in the previous patch.

Please use this one instead.

-- 
Olivier Certner

[-- Attachment #2: 0001-CC-Mode-Fix-K-R-argument-declaration-misdetection-af.patch --]
[-- Type: text/x-patch, Size: 2201 bytes --]

From 0515de23d84a48c57b456c6730f826c5d783b965 Mon Sep 17 00:00:00 2001
From: Olivier Certner <olce.emacs@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


  parent reply	other threads:[~2023-05-04 22:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04 21:54 bug#63285: 30.0.50; CC Mode: K&R argument declaration misdetection after parenthesized type Olivier Certner
     [not found] ` <handler.63285.B.168323729911280.ack@debbugs.gnu.org>
2023-05-04 21:57   ` bug#63285: Acknowledgement (30.0.50; CC Mode: K&R argument declaration misdetection after parenthesized type) Olivier Certner
2023-05-04 22:14 ` Olivier Certner [this message]
2023-10-05 20:43   ` bug#63285: 30.0.50; CC Mode: K&R argument declaration misdetection after parenthesized type Stefan Kangas
2023-10-06  9:09     ` Alan Mackenzie
2023-10-06 13:18     ` Alan Mackenzie
2023-10-13 14:38       ` Alan Mackenzie
2023-10-13 15:04         ` Stefan Kangas

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=2329887.yEB1Cff6dg@ravel \
    --to=ocert.dev@free.fr \
    --cc=63285@debbugs.gnu.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).