From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: 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 Message-ID: <20160401161819.GA3299@acm.fritz.box> References: <87k2lsuh96.fsf@gnus.org> <20160301180242.GA6494@acm.fritz.box> <56D5D9FB.2060605@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1459527389 1567 80.91.229.3 (1 Apr 2016 16:16:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Apr 2016 16:16:29 +0000 (UTC) Cc: 7918@debbugs.gnu.org, Lars Ingebrigtsen To: Daniel Colascione Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Apr 01 18:16:16 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1am1k6-0003N2-8t for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Apr 2016 18:16:14 +0200 Original-Received: from localhost ([::1]:45395 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1am1k5-000873-FC for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Apr 2016 12:16:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1am1k1-00086q-A6 for bug-gnu-emacs@gnu.org; Fri, 01 Apr 2016 12:16:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1am1ju-0002hp-Te for bug-gnu-emacs@gnu.org; Fri, 01 Apr 2016 12:16:09 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1am1ju-0002hY-PI; Fri, 01 Apr 2016 12:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1am1ju-00042s-Dm; Fri, 01 Apr 2016 12:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Fri, 01 Apr 2016 16:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 7918 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: patch confirmed Original-Received: via spool by 7918-submit@debbugs.gnu.org id=B7918.145952732715503 (code B ref 7918); Fri, 01 Apr 2016 16:16:02 +0000 Original-Received: (at 7918) by debbugs.gnu.org; 1 Apr 2016 16:15:27 +0000 Original-Received: from localhost ([127.0.0.1]:47502 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1am1jL-00041z-BK for submit@debbugs.gnu.org; Fri, 01 Apr 2016 12:15:27 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:60008) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1am1jJ-00041q-NE for 7918@debbugs.gnu.org; Fri, 01 Apr 2016 12:15:26 -0400 Original-Received: (qmail 99915 invoked by uid 3782); 1 Apr 2016 16:15:24 -0000 Original-Received: from acm.muc.de (p548A4E91.dip0.t-ipconnect.de [84.138.78.145]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 01 Apr 2016 18:15:22 +0200 Original-Received: (qmail 6015 invoked by uid 1000); 1 Apr 2016 16:18:19 -0000 Content-Disposition: inline In-Reply-To: <56D5D9FB.2060605@dancol.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:115844 Archived-At: 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 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).