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#7579: cc-mode c++ template-typed variable decl regression Date: Tue, 21 Feb 2012 14:05:26 +0000 Message-ID: <20120221140526.GA2787@acm.acm> References: <87d39h33jq.fsf@gnu.org> <20120214152443.GB15736@acm.acm> <20120214161153.GC15736@acm.acm> <4F3A96E9.8090507@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1329833225 10808 80.91.229.3 (21 Feb 2012 14:07:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 21 Feb 2012 14:07:05 +0000 (UTC) Cc: 7579@debbugs.gnu.org, Chong Yidong To: Daniel Colascione Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Feb 21 15:07:03 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RzqMr-0002Zd-DE for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 Feb 2012 15:06:57 +0100 Original-Received: from localhost ([::1]:53878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzqMq-0001sZ-QD for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 Feb 2012 09:06:56 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:55081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzqMi-0001sD-S6 for bug-gnu-emacs@gnu.org; Tue, 21 Feb 2012 09:06:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RzqMh-0006TP-Iz for bug-gnu-emacs@gnu.org; Tue, 21 Feb 2012 09:06:48 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44808) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzqMf-0006T8-Os; Tue, 21 Feb 2012 09:06:45 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1RzqOr-0000K1-Oa; Tue, 21 Feb 2012 09:09:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Tue, 21 Feb 2012 14:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 7579 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 7579-submit@debbugs.gnu.org id=B7579.13298333031188 (code B ref 7579); Tue, 21 Feb 2012 14:09:01 +0000 Original-Received: (at 7579) by debbugs.gnu.org; 21 Feb 2012 14:08:23 +0000 Original-Received: from localhost ([127.0.0.1]:48431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RzqOE-0000J7-GS for submit@debbugs.gnu.org; Tue, 21 Feb 2012 09:08:22 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:59424 helo=mail.muc.de) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RzqOB-0000Iy-If for 7579@debbugs.gnu.org; Tue, 21 Feb 2012 09:08:21 -0500 Original-Received: (qmail 24330 invoked by uid 3782); 21 Feb 2012 14:06:00 -0000 Original-Received: from acm.muc.de (pD9557375.dip.t-dialin.net [217.85.115.117]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 21 Feb 2012 15:05:55 +0100 Original-Received: (qmail 3715 invoked by uid 1000); 21 Feb 2012 14:05:26 -0000 Content-Disposition: inline In-Reply-To: <4F3A96E9.8090507@dancol.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.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:57044 Archived-At: Hello, Daniel. On Tue, Feb 14, 2012 at 09:16:25AM -0800, Daniel Colascione wrote: > Hi Alan, > On 2/14/12 8:11 AM, Alan Mackenzie wrote: > >>>> /* In Emacs 23, adffdfa below is fontified as a variable. In Emacs HEAD, > >>>> it is not. */ > >>>> void foo() > >>>> { > >>>> mumble x(5); > >>>> std::vector adffdfa(1,2,3); > >>>> }; > >> Are there any syntactic clues here that a variable rather than a function > >> is being declared? All I can see is that numeric literals take the place > >> of "parameters". > > Please ignore this request. Obviously, for a function, there must be > > either nothing in the parentheses or [ ]*. > Or just types: > std::vector blah(int); > typedef int foo; > std::vector blah(foo); > Still, unless we're absolutely sure we're looking at a function > declaration, we should fontify a declaration as a variables > declaration. Function-scope function declarations are extremely > uncommon, and at least in my experience, almost always offset by > keywords like "extern". Even if something like int bar(); could be a > function, fontifying it as a variable would be the right thing to do > in function scope for C++. OK, here's a patch to try out. As you requested, everything which might look like a function which is directly within a function is treated as a variable declaration, with one exception. That is a construct like int (*foo) (bar); , where foo continues to be a function. If you can think of any other constructs which should still be functions, please let me know. Please give the patch a stress test and let me know how it works. diff -r 9e9f3f646393 cc-fonts.el --- a/cc-fonts.el Sun Feb 19 18:19:16 2012 +0000 +++ b/cc-fonts.el Tue Feb 21 13:58:37 2012 +0000 @@ -1009,6 +1009,7 @@ paren-depth id-face got-init c-last-identifier-range + maybe-function-type (separator-prop (if types 'c-decl-type-start 'c-decl-id-start))) ;; The following `while' fontifies a single declarator id each time round. @@ -1054,7 +1055,10 @@ (if (eq (char-after) ?\() (progn (setq paren-depth (1+ paren-depth)) - (forward-char)) + (forward-char) + (c-forward-syntactic-ws) + (setq maybe-function-type + (eq (char-after) ?*))) (goto-char (match-end 1))) (c-forward-syntactic-ws)) @@ -1088,7 +1092,15 @@ "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t)) (setq next-pos (match-beginning 0) - id-face (if (eq (char-after next-pos) ?\() + id-face (if (and (eq (char-after next-pos) ?\() + (or maybe-function-type + (not (and (c-major-mode-is 'c++-mode) + (let (c-last-identifier-range + c-record-type-identifiers) + (save-excursion + (goto-char id-start) + (not (c-at-toplevel-p)))))))) + 'font-lock-function-name-face 'font-lock-variable-name-face) got-init (and (match-beginning 1) @@ -1141,6 +1153,7 @@ ;; If a ',' is found we set pos to the next declarator and iterate. (when (and (< (point) limit) (looking-at ",")) + (setq maybe-function-type nil) (c-put-char-property (point) 'c-type separator-prop) (forward-char) (c-forward-syntactic-ws limit) -- Alan Mackenzie (Nuremberg, Germany).