GNU bug report logs - #7918
[PATCH] cc-mode: only the first clause of a for-loop should be checked for declarations

Previous Next

Packages: emacs, cc-mode;

Reported by: Daniel Colascione <dan.colascione <at> gmail.com>

Date: Wed, 26 Jan 2011 06:29:02 UTC

Severity: minor

Tags: confirmed, fixed, patch

Found in version 25.2

Fixed in version 26.1

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

Full log


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

From: Alan Mackenzie <acm <at> muc.de>
To: Daniel Colascione <dancol <at> dancol.org>
Cc: 7918 <at> debbugs.gnu.org, Lars Ingebrigtsen <larsi <at> gnus.org>
Subject: Re: bug#7918: [PATCH] cc-mode: only the first clause of a for-loop
 should be checked for declarations
Date: Fri, 1 Apr 2016 16:18:19 +0000
Hello, Daniel.

On Tue, Mar 01, 2016 at 10:05:47AM -0800, Daniel Colascione wrote:
> On 03/01/2016 10:02 AM, Alan Mackenzie wrote:

> > On Fri, Feb 26, 2016 at 04:48:13PM +1030, Lars Ingebrigtsen wrote:
> >> Daniel Colascione <dan.colascione <at> gmail.com> writes:

> >>> // This code has no variable declarations

> >>> void foo() {
> >>>     for (; (DWORD) a * b ;)
> >>>         ;

> >>>     for (; a * b ;)
> >>>         ;
> >>> }


> It's been years since I even thought about that code. If you're up for
> it, I'd rather you supply a separate fix.

OK, here goes:


diff -r f19a4ffb060b cc-fonts.el
--- a/cc-fonts.el	Fri Apr 01 12:23:17 2016 +0000
+++ b/cc-fonts.el	Fri Apr 01 16:10:57 2016 +0000
@@ -1206,8 +1206,20 @@
 			   'font-lock-keyword-face)
 		       (looking-at c-not-decl-init-keywords))
 		  (and c-macro-with-semi-re
-		       (looking-at c-macro-with-semi-re))) ; 2008-11-04
-	      ;; Don't do anything more if we're looking at a keyword that
+		       (looking-at c-macro-with-semi-re)) ; 2008-11-04
+		  (save-excursion ; A construct after a ; in a `for' statement
+				  ; can't be a declaration.
+		    (and (c-go-up-list-backward)
+			 (eq (char-after) ?\()
+			 (progn (c-backward-syntactic-ws)
+				(c-simple-skip-symbol-backward))
+			 (looking-at c-paren-stmt-key)
+			 (progn (goto-char match-pos)
+				(while (and (eq (char-before) ?\))
+					    (c-go-list-backward))
+				  (c-backward-syntactic-ws))
+				(eq (char-before) ?\;)))))
+	      ;; Don't do anything more if we're looking at something that
 	      ;; can't start a declaration.
 	      t
 

Could you do the usual with this patch, please, then if everything's OK,
I can commit it to the emacs-25 branch.  Thanks!

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 8 years and 13 days ago.

Previous Next


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