unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#7917: [PATCH] cc-mode: not all templates are types
@ 2011-01-26  6:29 Daniel Colascione
  2016-02-26  6:22 ` Lars Ingebrigtsen
  2016-04-01 13:07 ` Alan Mackenzie
  0 siblings, 2 replies; 10+ messages in thread
From: Daniel Colascione @ 2011-01-26  6:29 UTC (permalink / raw)
  To: 7917

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

None of the templates here should be fontified as types.

template<typename T>
void foo(T t)
{}

template<>
void foo<int>(int x)
{}

void bar()
{
    foo<int>(5);
}

[-- Attachment #2: templatefunc.patch --]
[-- Type: text/plain, Size: 2413 bytes --]

=== modified file 'lisp/progmodes/cc-engine.el'
--- lisp/progmodes/cc-engine.el	2010-12-09 07:52:58 +0000
+++ lisp/progmodes/cc-engine.el	2011-01-26 05:06:59 +0000
@@ -5850,11 +5850,12 @@
 	       (when (let ((c-record-type-identifiers t)
 			   (c-record-found-types t))
 		       (c-forward-<>-arglist nil))
-
-		 (c-add-type start (1+ pos))
+		 
 		 (c-forward-syntactic-ws)
-		 (setq pos (point)
-		       c-last-identifier-range nil)
+		 (unless (eq (char-after) ?\()
+		   (setq c-last-identifier-range nil)
+		   (c-add-type start (1+ pos)))
+		 (setq pos (point))
 
 		 (if (and c-opt-identifier-concat-key
 			  (looking-at c-opt-identifier-concat-key))
@@ -5868,7 +5869,8 @@
 		       (c-forward-syntactic-ws)
 		       t)
 
-		   (when (and c-record-type-identifiers id-start)
+		   (when (and c-record-type-identifiers id-start
+			      (not (eq (char-after) ?\()))
 		     (c-record-type-id (cons id-start id-end)))
 		   (setq res 'template)
 		   nil)))
@@ -6054,9 +6056,17 @@
 			   ;; It's an identifier that might be a type.
 			   'maybe))))
 	    ((eq name-res 'template)
-	     ;; A template is a type.
+	     ;; A template is sometimes a type.
 	     (goto-char id-end)
-	     (setq res t))
+	     (setq res
+		   (if (eq (char-after) ?\()
+		       (if (c-check-type id-start id-end)
+			   ;; It's an identifier that has been used as
+			   ;; a type somewhere else.
+			   'found
+			 ;; It's an identifier that might be a type.
+			 'maybe)
+		     t)))
 	    (t
 	     ;; Otherwise it's an operator identifier, which is not a type.
 	     (goto-char start)

=== modified file 'lisp/progmodes/cc-fonts.el'
--- lisp/progmodes/cc-fonts.el	2011-01-25 11:20:25 +0000
+++ lisp/progmodes/cc-fonts.el	2011-01-25 12:58:26 +0000
@@ -835,11 +835,12 @@
 		    (when (and c-opt-identifier-concat-key
 			       (not (get-text-property id-start 'face)))
 		      (c-forward-syntactic-ws)
-		      (if (looking-at c-opt-identifier-concat-key)
-			  (c-put-font-lock-face id-start id-end
-						c-reference-face-name)
-			(c-put-font-lock-face id-start id-end
-					      'font-lock-type-face)))))
+		      (cond ((looking-at c-opt-identifier-concat-key)
+			     (c-put-font-lock-face id-start id-end
+						c-reference-face-name))
+			    ((eq (char-after) ?\())
+			    (t (c-put-font-lock-face id-start id-end
+					      'font-lock-type-face))))))
 
 		(goto-char pos)))
 	  (goto-char pos)))))


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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2011-01-26  6:29 bug#7917: [PATCH] cc-mode: not all templates are types Daniel Colascione
@ 2016-02-26  6:22 ` Lars Ingebrigtsen
  2016-02-26  6:30   ` Daniel Colascione
  2016-04-01 13:07 ` Alan Mackenzie
  1 sibling, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-26  6:22 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: 7917

Daniel Colascione <dan.colascione@gmail.com> writes:

> None of the templates here should be fontified as types.
>
> template<typename T>
> void foo(T t)
> {}
>
> template<>
> void foo<int>(int x)
> {}
>
> void bar()
> {
>     foo<int>(5);
> }

On the Emacs trunk, I can't see anything immediately wrong about the
fontification of the templates -- they're all fontified with the keyword
face.

So has this been fixed in the meantime (just five years)?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2016-02-26  6:22 ` Lars Ingebrigtsen
@ 2016-02-26  6:30   ` Daniel Colascione
  2016-02-26  7:10     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Colascione @ 2016-02-26  6:30 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Daniel Colascione; +Cc: 7917

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

On 02/25/2016 10:22 PM, Lars Ingebrigtsen wrote:
> Daniel Colascione <dan.colascione@gmail.com> writes:
> 
>> None of the templates here should be fontified as types.
>>
>> template<typename T>
>> void foo(T t)
>> {}
>>
>> template<>
>> void foo<int>(int x)
>> {}
>>
>> void bar()
>> {
>>     foo<int>(5);
>> }
> 
> On the Emacs trunk, I can't see anything immediately wrong about the
> fontification of the templates -- they're all fontified with the keyword
> face.
> 
> So has this been fixed in the meantime (just five years)?
> 

For me --- empty scratch buffer, c++-mode, emacs -Q, pasting in
this example, the name of the second function is fontified as a type,
not a function name. In the third function, in the call to foo<int>, foo
is also fontified as a type, although it shouldn't be fontified as
anything at all.


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

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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2016-02-26  6:30   ` Daniel Colascione
@ 2016-02-26  7:10     ` Lars Ingebrigtsen
  2016-02-27  4:03       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-26  7:10 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: Daniel Colascione, 7917

Daniel Colascione <dancol@dancol.org> writes:

> For me --- empty scratch buffer, c++-mode, emacs -Q, pasting in
> this example, the name of the second function is fontified as a type,
> not a function name. In the third function, in the call to foo<int>, foo
> is also fontified as a type, although it shouldn't be fontified as
> anything at all.

Oh, yeah, that's true.  

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2016-02-26  7:10     ` Lars Ingebrigtsen
@ 2016-02-27  4:03       ` Lars Ingebrigtsen
  2016-02-28 21:32         ` Alan Mackenzie
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-27  4:03 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: dan.colascione, 7917

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Daniel Colascione <dancol@dancol.org> writes:
>
>> For me --- empty scratch buffer, c++-mode, emacs -Q, pasting in
>> this example, the name of the second function is fontified as a type,
>> not a function name. In the third function, in the call to foo<int>, foo
>> is also fontified as a type, although it shouldn't be fontified as
>> anything at all.
>
> Oh, yeah, that's true.  

And your patch fixes the issue.  Does anybody have any objections to
applying the patch?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2016-02-27  4:03       ` Lars Ingebrigtsen
@ 2016-02-28 21:32         ` Alan Mackenzie
  2016-02-29  2:51           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2016-02-28 21:32 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: dan.colascione, 7917

Hello, Lars.

On Sat, Feb 27, 2016 at 02:33:36PM +1030, Lars Ingebrigtsen wrote:
> Lars Ingebrigtsen <larsi@gnus.org> writes:

> > Daniel Colascione <dancol@dancol.org> writes:

> >> For me --- empty scratch buffer, c++-mode, emacs -Q, pasting in
> >> this example, the name of the second function is fontified as a type,
> >> not a function name. In the third function, in the call to foo<int>, foo
> >> is also fontified as a type, although it shouldn't be fontified as
> >> anything at all.

> > Oh, yeah, that's true.  

> And your patch fixes the issue.  Does anybody have any objections to
> applying the patch?

The patch breaks the fontification of certain Java constructs, in
particular, ones looking like this:

    Map<String, Driver> allDrivers = new Map<String, Driver>();
                                         ^^^

With the patch in place, the indicated "Map" doesn't get fontified in
font-lock-type-face as it should.

Before applying any patches like this to CC Mode, could you please run
them through the CC Mode test suite first (or ask Daniel (the OP) or me
to do it).  Thanks!

> -- 
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no

-- 
Alan Mackenzie (Nuremberg, Germany).





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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2016-02-28 21:32         ` Alan Mackenzie
@ 2016-02-29  2:51           ` Lars Ingebrigtsen
  2016-02-29 22:14             ` Alan Mackenzie
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-29  2:51 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: dan.colascione, 7917

Alan Mackenzie <acm@muc.de> writes:

> Before applying any patches like this to CC Mode, could you please run
> them through the CC Mode test suite first (or ask Daniel (the OP) or me
> to do it).  Thanks!

Is the CC Mode test suite included in the Emacs test/ directory
somewhere?  I looked around and didn't really find anything...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2016-02-29  2:51           ` Lars Ingebrigtsen
@ 2016-02-29 22:14             ` Alan Mackenzie
  0 siblings, 0 replies; 10+ messages in thread
From: Alan Mackenzie @ 2016-02-29 22:14 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: dan.colascione, 7917

Hello, Lars.

On Mon, Feb 29, 2016 at 01:51:29PM +1100, Lars Ingebrigtsen wrote:
> Alan Mackenzie <acm@muc.de> writes:

> > Before applying any patches like this to CC Mode, could you please run
> > them through the CC Mode test suite first (or ask Daniel (the OP) or me
> > to do it).  Thanks!

> Is the CC Mode test suite included in the Emacs test/ directory
> somewhere?  I looked around and didn't really find anything...

No, it's only in CC Mode (the project) itself.  It's build up from
around 400 mostly small source files, each of which tests either
indentation, fontification, or both, together with an elisp file which
drives everything.

The (Mercurial) repository of CC Mode can be found via
<http://cc-mode@sourceforge.net/hgaccess.php>.

-- 
Alan Mackenzie (Nuremberg, Germany).





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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2011-01-26  6:29 bug#7917: [PATCH] cc-mode: not all templates are types Daniel Colascione
  2016-02-26  6:22 ` Lars Ingebrigtsen
@ 2016-04-01 13:07 ` Alan Mackenzie
  2017-06-29  1:02   ` npostavs
  1 sibling, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2016-04-01 13:07 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: 7917

Hello, Daniel.

I've committed a fix for bug #7917 into the emacs-25 branch.  It's
basically your patch, but with one or two extra bits to cope with a
nasty little problem it caused in a Java Mode test file.

Would you try it out, please, and confirm that it has indeed fixed the
bug, or let me know what is still wrong.  Thanks!

-- 
Alan Mackenzie (Nuremberg, Germany).



On Tue, Jan 25, 2011 at 10:29:01PM -0800, Daniel Colascione wrote:
> None of the templates here should be fontified as types.

> template<typename T>
> void foo(T t)
> {}

> template<>
> void foo<int>(int x)
> {}

> void bar()
> {
>     foo<int>(5);
> }

> === modified file 'lisp/progmodes/cc-engine.el'
> --- lisp/progmodes/cc-engine.el	2010-12-09 07:52:58 +0000
> +++ lisp/progmodes/cc-engine.el	2011-01-26 05:06:59 +0000
> @@ -5850,11 +5850,12 @@
>  	       (when (let ((c-record-type-identifiers t)
>  			   (c-record-found-types t))
>  		       (c-forward-<>-arglist nil))
> -
> -		 (c-add-type start (1+ pos))
> +		 
>  		 (c-forward-syntactic-ws)
> -		 (setq pos (point)
> -		       c-last-identifier-range nil)
> +		 (unless (eq (char-after) ?\()
> +		   (setq c-last-identifier-range nil)
> +		   (c-add-type start (1+ pos)))
> +		 (setq pos (point))
 
>  		 (if (and c-opt-identifier-concat-key
>  			  (looking-at c-opt-identifier-concat-key))
> @@ -5868,7 +5869,8 @@
>  		       (c-forward-syntactic-ws)
>  		       t)
 
> -		   (when (and c-record-type-identifiers id-start)
> +		   (when (and c-record-type-identifiers id-start
> +			      (not (eq (char-after) ?\()))
>  		     (c-record-type-id (cons id-start id-end)))
>  		   (setq res 'template)
>  		   nil)))
> @@ -6054,9 +6056,17 @@
>  			   ;; It's an identifier that might be a type.
>  			   'maybe))))
>  	    ((eq name-res 'template)
> -	     ;; A template is a type.
> +	     ;; A template is sometimes a type.
>  	     (goto-char id-end)
> -	     (setq res t))
> +	     (setq res
> +		   (if (eq (char-after) ?\()
> +		       (if (c-check-type id-start id-end)
> +			   ;; It's an identifier that has been used as
> +			   ;; a type somewhere else.
> +			   'found
> +			 ;; It's an identifier that might be a type.
> +			 'maybe)
> +		     t)))
>  	    (t
>  	     ;; Otherwise it's an operator identifier, which is not a type.
>  	     (goto-char start)

> === modified file 'lisp/progmodes/cc-fonts.el'
> --- lisp/progmodes/cc-fonts.el	2011-01-25 11:20:25 +0000
> +++ lisp/progmodes/cc-fonts.el	2011-01-25 12:58:26 +0000
> @@ -835,11 +835,12 @@
>  		    (when (and c-opt-identifier-concat-key
>  			       (not (get-text-property id-start 'face)))
>  		      (c-forward-syntactic-ws)
> -		      (if (looking-at c-opt-identifier-concat-key)
> -			  (c-put-font-lock-face id-start id-end
> -						c-reference-face-name)
> -			(c-put-font-lock-face id-start id-end
> -					      'font-lock-type-face)))))
> +		      (cond ((looking-at c-opt-identifier-concat-key)
> +			     (c-put-font-lock-face id-start id-end
> +						c-reference-face-name))
> +			    ((eq (char-after) ?\())
> +			    (t (c-put-font-lock-face id-start id-end
> +					      'font-lock-type-face))))))
 
>  		(goto-char pos)))
>  	  (goto-char pos)))))






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

* bug#7917: [PATCH] cc-mode: not all templates are types
  2016-04-01 13:07 ` Alan Mackenzie
@ 2017-06-29  1:02   ` npostavs
  0 siblings, 0 replies; 10+ messages in thread
From: npostavs @ 2017-06-29  1:02 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Daniel Colascione, 7917

found 7917 24.5
severity 7917 minor
tags 7917 fixed
close 7917 25.1
quit

Alan Mackenzie <acm@muc.de> writes:

> I've committed a fix for bug #7917 into the emacs-25 branch.  It's
> basically your patch, but with one or two extra bits to cope with a
> nasty little problem it caused in a Java Mode test file.
>
> Would you try it out, please, and confirm that it has indeed fixed the
> bug, or let me know what is still wrong.  Thanks!

I can see the bug in 24.5, but not in 25.1





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

end of thread, other threads:[~2017-06-29  1:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-26  6:29 bug#7917: [PATCH] cc-mode: not all templates are types Daniel Colascione
2016-02-26  6:22 ` Lars Ingebrigtsen
2016-02-26  6:30   ` Daniel Colascione
2016-02-26  7:10     ` Lars Ingebrigtsen
2016-02-27  4:03       ` Lars Ingebrigtsen
2016-02-28 21:32         ` Alan Mackenzie
2016-02-29  2:51           ` Lars Ingebrigtsen
2016-02-29 22:14             ` Alan Mackenzie
2016-04-01 13:07 ` Alan Mackenzie
2017-06-29  1:02   ` npostavs

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