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#63285: 30.0.50; CC Mode: K&R argument declaration misdetection after parenthesized type Date: Fri, 6 Oct 2023 13:18:01 +0000 Message-ID: References: <51034426.rt4x2z8vUf@ravel> <2329887.yEB1Cff6dg@ravel> 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="16419"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, 63285@debbugs.gnu.org To: Olivier Certner , Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 06 15:18:58 2023 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 1qokjK-00040f-DD for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 06 Oct 2023 15:18:58 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qokj6-0004T5-ON; Fri, 06 Oct 2023 09:18:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qokj5-0004RC-Kd for bug-gnu-emacs@gnu.org; Fri, 06 Oct 2023 09:18:43 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qokj5-0002Mw-CI for bug-gnu-emacs@gnu.org; Fri, 06 Oct 2023 09:18:43 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qokjO-0003qw-4t for bug-gnu-emacs@gnu.org; Fri, 06 Oct 2023 09:19: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: Fri, 06 Oct 2023 13:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63285 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 63285-submit@debbugs.gnu.org id=B63285.169659831014761 (code B ref 63285); Fri, 06 Oct 2023 13:19:02 +0000 Original-Received: (at 63285) by debbugs.gnu.org; 6 Oct 2023 13:18:30 +0000 Original-Received: from localhost ([127.0.0.1]:49453 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qokir-0003q1-NZ for submit@debbugs.gnu.org; Fri, 06 Oct 2023 09:18:30 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:34767) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qokiq-0003pn-5K for 63285@debbugs.gnu.org; Fri, 06 Oct 2023 09:18:28 -0400 Original-Received: (qmail 30135 invoked by uid 3782); 6 Oct 2023 15:18:02 +0200 Original-Received: from acm.muc.de (pd953a487.dip0.t-ipconnect.de [217.83.164.135]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 06 Oct 2023 15:18:02 +0200 Original-Received: (qmail 6610 invoked by uid 1000); 6 Oct 2023 13:18:01 -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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:271947 Archived-At: Hello, Olivier and Stefan. On Thu, Oct 05, 2023 at 20:43:24 +0000, Stefan Kangas wrote: > Olivier Certner 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 > > 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).