unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#7579: cc-mode c++ template-typed variable decl regression
@ 2010-12-07 10:55 Daniel Colascione
  2010-12-07 13:17 ` Daniel Colascione
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Daniel Colascione @ 2010-12-07 10:55 UTC (permalink / raw)
  To: 7579

[-- Attachment #1: Type: text/plain, Size: 170 bytes --]

/* 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);
};



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  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
  2016-02-04 19:09 ` Alan Mackenzie
  2 siblings, 0 replies; 10+ messages in thread
From: Daniel Colascione @ 2010-12-07 13:17 UTC (permalink / raw)
  To: bug-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/7/10 2:55 AM, Daniel Colascione 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);
> };
> 
> 

Never mind --- this is a manifestation of bug 7405.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)

iEYEARECAAYFAkz+M/cACgkQ17c2LVA10Vsp7ACfYNwuW/aL4C1YOETbpX1gwwsz
GN8AoMZOP22xLEeTaB0btb5vD4YdQapI
=DP2/
-----END PGP SIGNATURE-----






^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  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
  2016-02-04 19:09 ` Alan Mackenzie
  2 siblings, 1 reply; 10+ messages in thread
From: Chong Yidong @ 2012-02-14 14:14 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 7579

Hi Alan,

Could you take a look at Bug#7579 too?  Thanks:


Daniel Colascione <dan.colascione@gmail.com> 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);
> };





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  2012-02-14 14:14 ` Chong Yidong
@ 2012-02-14 15:24   ` Alan Mackenzie
  2012-02-14 16:11     ` Alan Mackenzie
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2012-02-14 15:24 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: 7579, Chong Yidong

Hi, Daniel.

On Tue, Feb 14, 2012 at 10:14:33PM +0800, Chong Yidong wrote:
> Hi Alan,

> Could you take a look at Bug#7579 too?  Thanks:


> Daniel Colascione <dan.colascione@gmail.com> 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".

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Alan Mackenzie @ 2012-02-14 16:11 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: 7579, Chong Yidong

Hello again,

On Tue, Feb 14, 2012 at 03:24:43PM +0000, Alan Mackenzie wrote:
> Hi, Daniel.

> On Tue, Feb 14, 2012 at 10:14:33PM +0800, Chong Yidong wrote:
> > Hi Alan,

> > Could you take a look at Bug#7579 too?  Thanks:


> > Daniel Colascione <dan.colascione@gmail.com> 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>]*.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  2012-02-14 16:11     ` Alan Mackenzie
@ 2012-02-14 17:12       ` Andreas Schwab
  2012-02-14 17:16       ` Daniel Colascione
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2012-02-14 17:12 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 7579, Chong Yidong, Daniel Colascione

Alan Mackenzie <acm@muc.de> writes:

> Please ignore this request.  Obviously, for a function, there must be
> either nothing in the parentheses or  [<type> <value>]*.

It can also be just a list of types.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Daniel Colascione @ 2012-02-14 17:16 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 7579, Chong Yidong, Daniel Colascione

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

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++.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 235 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  2012-02-14 17:16       ` Daniel Colascione
@ 2012-02-21 14:05         ` Alan Mackenzie
  0 siblings, 0 replies; 10+ messages in thread
From: Alan Mackenzie @ 2012-02-21 14:05 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: 7579, Chong Yidong

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).





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  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
@ 2016-02-04 19:09 ` Alan Mackenzie
  2016-02-04 19:17   ` Daniel Colascione
  2 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2016-02-04 19:09 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: 7579-done

Hello, Daniel.

On Tue, Dec 07, 2010 at 02:55:00AM -0800, Daniel Colascione 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);
> };

The bug has been fixed in the emacs-25 branch.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7579: cc-mode c++ template-typed variable decl regression
  2016-02-04 19:09 ` Alan Mackenzie
@ 2016-02-04 19:17   ` Daniel Colascione
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Colascione @ 2016-02-04 19:17 UTC (permalink / raw)
  To: Alan Mackenzie, Daniel Colascione; +Cc: 7579-done

[-- Attachment #1: Type: text/plain, Size: 395 bytes --]

On 02/04/2016 11:09 AM, Alan Mackenzie wrote:
> Hello, Daniel.
> 
> On Tue, Dec 07, 2010 at 02:55:00AM -0800, Daniel Colascione 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);
>> };
> 
> The bug has been fixed in the emacs-25 branch.

Thanks!


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-02-04 19:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-02-04 19:09 ` Alan Mackenzie
2016-02-04 19:17   ` Daniel Colascione

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).