all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Daniel Colascione <dancol@dancol.org>
Cc: 7579@debbugs.gnu.org, Chong Yidong <cyd@gnu.org>
Subject: bug#7579: cc-mode c++ template-typed variable decl regression
Date: Tue, 21 Feb 2012 14:05:26 +0000	[thread overview]
Message-ID: <20120221140526.GA2787@acm.acm> (raw)
In-Reply-To: <4F3A96E9.8090507@dancol.org>

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<int> 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  [<type> <value>]*.

> Or just types:

> std::vector <int> blah(int);

> typedef int foo;
> std::vector <int> 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).





  reply	other threads:[~2012-02-21 14:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-07 10:55 bug#7579: cc-mode c++ template-typed variable decl regression Daniel Colascione
2010-12-07 13:17 ` Daniel Colascione
2012-02-14 14:14 ` Chong Yidong
2012-02-14 15:24   ` Alan Mackenzie
2012-02-14 16:11     ` Alan Mackenzie
2012-02-14 17:12       ` Andreas Schwab
2012-02-14 17:16       ` Daniel Colascione
2012-02-21 14:05         ` Alan Mackenzie [this message]
2016-02-04 19:09 ` Alan Mackenzie
2016-02-04 19:17   ` Daniel Colascione

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120221140526.GA2787@acm.acm \
    --to=acm@muc.de \
    --cc=7579@debbugs.gnu.org \
    --cc=cyd@gnu.org \
    --cc=dancol@dancol.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.