GNU bug report logs -
#23610
25.0.94; c++-mode doesn't fontify typename... like typename
Previous Next
Reported by: Ivan Andrus <darthandrus <at> gmail.com>
Date: Tue, 24 May 2016 17:02:02 UTC
Severity: minor
Found in version 25.0.94
Done: Alan Mackenzie <acm <at> muc.de>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 23610 in the body.
You can then email your comments to 23610 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23610
; Package
emacs
.
(Tue, 24 May 2016 17:02:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Ivan Andrus <darthandrus <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 24 May 2016 17:02:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Starting with emacs -Q, Y is not fontified in the snippet below, whereas
X is.
-Ivan
template <typename X, typename... Y>
class bob {
};
In GNU Emacs 25.0.94.2 (x86_64-apple-darwin15.4.0, NS appkit-1404.46
Version 10.11.4 (Build 15E65))
of 2016-05-22 built on iandrus-osx
Repository revision: ae8352b8219b3d40f70fda8986ae86fbef7322fb
Windowing system distributor 'Apple', version 10.3.1404
Configured using:
'configure --with-ns --with-modules
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig'
Configured features:
JPEG RSVG IMAGEMAGICK DBUS NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS NS MODULES
Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
Major mode: C++/l
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
abbrev-mode: t
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
user-error: The mark is not set now, so there is no region
Undo!
<C-s-268632064> is undefined
user-error: The mark is not set now, so there is no region
user-error: No mark set in this buffer
Mark set
Undo!
Load-path shadows:
None found.
Features:
(shadow sort mail-extr emacsbug message dired format-spec rfc822 mml
mml-sec password-cache epg epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util help-fns mail-prsvr mail-utils
cl-extra help-mode cc-mode cc-fonts easymenu cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs cl-loaddefs pcase cl-lib
time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel ns-win ucs-normalize term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment elisp-mode
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame
cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese charscript
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind kqueue cocoa
ns multi-tty make-network-process emacs)
Memory information:
((conses 16 216680 9514)
(symbols 48 22190 2)
(miscs 40 50 243)
(strings 32 20775 6226)
(string-bytes 1 712665)
(vectors 16 35464)
(vector-slots 8 687847 4136)
(floats 8 163 110)
(intervals 56 332 8)
(buffers 976 11))
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Mon, 30 May 2016 12:58:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 23610 <at> debbugs.gnu.org (full text, mbox):
Hello, Ivan.
In article <mailman.202.1464109329.1216.bug-gnu-emacs <at> gnu.org> you wrote:
> Starting with emacs -Q, Y is not fontified in the snippet below, whereas
> X is.
I'm not all that familiar with variadic templates. In the declaration
below, is the "..." token syntactically part of "typename..." or is
better regarded as part of "... Y"?
I also need to get a feel for what keywords can come before the "...".
Obviously "typename", but what about things like "class"?
Do you know of a good web page where these things are explained
completely and concisely, yet readably? If so, please tell me!
> -Ivan
> template <typename X, typename... Y>
> class bob {
> };
> In GNU Emacs 25.0.94.2 (x86_64-apple-darwin15.4.0, NS appkit-1404.46
> Version 10.11.4 (Build 15E65))
> of 2016-05-22 built on iandrus-osx
> Repository revision: ae8352b8219b3d40f70fda8986ae86fbef7322fb
> Windowing system distributor 'Apple', version 10.3.1404
> Configured using:
> 'configure --with-ns --with-modules
> PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig'
[ .... ]
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Mon, 30 May 2016 13:51:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 23610 <at> debbugs.gnu.org (full text, mbox):
Hello Alan.
Alan Mackenzie <acm <at> muc.de> writes:
> I'm not all that familiar with variadic templates. In the declaration
> below, is the "..." token syntactically part of "typename..." or is
> better regarded as part of "... Y"?
Neiter, I'll say.
It is legal to omit the name of the parameter pack (the `Y' in the
example).
> I also need to get a feel for what keywords can come before the "...".
> Obviously "typename", but what about things like "class"?
Yes, `class' and `typename' are interchangeable here. There is also
`sizeof':
template <typename ... Ts> struct Foo {
void print() {
printf("Intantiated with %d parameters.\n", sizeof...(Ts));
}
};
int main() {
Foo<int, double> foo;
foo.print();
return 0;
}
Prints
Intantiated with 2 parameters.
> Do you know of a good web page where these things are explained
> completely and concisely, yet readably? If so, please tell me!
Try this, which is short and precise:
http://en.cppreference.com/w/cpp/language/parameter_pack
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Mon, 30 May 2016 15:26:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 23610 <at> debbugs.gnu.org (full text, mbox):
Hello, Óscar.
Thanks for your post!
On Mon, May 30, 2016 at 03:49:57PM +0200, Óscar Fuentes wrote:
> Hello Alan.
> Alan Mackenzie <acm <at> muc.de> writes:
> > I'm not all that familiar with variadic templates. In the declaration
> > below, is the "..." token syntactically part of "typename..." or is
> > better regarded as part of "... Y"?
> Neither, I'll say.
> It is legal to omit the name of the parameter pack (the `Y' in the
> example).
> > I also need to get a feel for what keywords can come before the "...".
> > Obviously "typename", but what about things like "class"?
> Yes, `class' and `typename' are interchangeable here. There is also
> `sizeof':
I thought there might be something like that. ;-)
> template <typename ... Ts> struct Foo {
> void print() {
> printf("Instantiated with %d parameters.\n", sizeof...(Ts));
> }
> };
> int main() {
> Foo<int, double> foo;
> foo.print();
> return 0;
> }
> Prints
> Intantiated with 2 parameters.
> > Do you know of a good web page where these things are explained
> > completely and concisely, yet readably? If so, please tell me!
> Try this, which is short and precise:
> http://en.cppreference.com/w/cpp/language/parameter_pack
That looks like exactly what I need. Thanks very much!
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Sun, 19 Jun 2016 21:15:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 23610 <at> debbugs.gnu.org (full text, mbox):
Hello, Ivan.
In article <mailman.202.1464109329.1216.bug-gnu-emacs <at> gnu.org> you wrote:
> Starting with emacs -Q, Y is not fontified in the snippet below, whereas
> X is.
> -Ivan
> template <typename X, typename... Y>
> class bob {
> };
[ .... ]
The following patch is a first attempt to fontify parameter packs. After
applying it, please be sure either to recompile CC Mode entirely, or
first to compile cc-langs.el (which contains macros), and then all three
of cc-fonts.el, cc-engine.el, and cc-mode.el.
It seems to fontify the "Y" above OK. I've tried it on a stock example
out of Wikipedia, and that works. Could you try it out on your code,
please, and let me know how well it works.
Here's the patch:
diff -r f70569e7cf8e cc-engine.el
--- a/cc-engine.el Sun Jun 19 11:54:55 2016 +0000
+++ b/cc-engine.el Sun Jun 19 21:05:32 2016 +0000
@@ -6910,6 +6910,9 @@
(while (cond
((looking-at c-decl-hangon-key)
(c-forward-keyword-clause 1))
+ ((looking-at c-pack-key)
+ (goto-char (match-end 1))
+ (c-forward-syntactic-ws))
((and c-opt-cpp-prefix
(looking-at c-noise-macro-with-parens-name-re))
(c-forward-noise-clause))))
diff -r f70569e7cf8e cc-langs.el
--- a/cc-langs.el Sun Jun 19 11:54:55 2016 +0000
+++ b/cc-langs.el Sun Jun 19 21:05:32 2016 +0000
@@ -1304,6 +1304,14 @@
(c-lang-defvar c-stmt-delim-chars-with-comma
(c-lang-const c-stmt-delim-chars-with-comma))
+(c-lang-defconst c-pack-ops
+ "Ops which signal C++11's \"parameter pack\""
+ t nil
+ c++ '("..."))
+(c-lang-defconst c-pack-key
+ t (c-make-keywords-re 'appendable (c-lang-const c-pack-ops)))
+(c-lang-defvar c-pack-key (c-lang-const c-pack-key))
+
(c-lang-defconst c-auto-ops
;; Ops which signal C++11's new auto uses.
t nil
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Wed, 22 Jun 2016 15:23:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 23610 <at> debbugs.gnu.org (full text, mbox):
On Sun, Jun 19, 2016 at 3:14 PM, Alan Mackenzie <acm <at> muc.de> wrote:
> Hello, Ivan.
>
> In article <mailman.202.1464109329.1216.bug-gnu-emacs <at> gnu.org> you wrote:
>> Starting with emacs -Q, Y is not fontified in the snippet below, whereas
>> X is.
>
>> -Ivan
>
>
>> template <typename X, typename... Y>
>> class bob {
>
>> };
>
> [ .... ]
>
> The following patch is a first attempt to fontify parameter packs. After
> applying it, please be sure either to recompile CC Mode entirely, or
> first to compile cc-langs.el (which contains macros), and then all three
> of cc-fonts.el, cc-engine.el, and cc-mode.el.
>
> It seems to fontify the "Y" above OK. I've tried it on a stock example
> out of Wikipedia, and that works. Could you try it out on your code,
> please, and let me know how well it works.
It looks pretty good. I didn't notice this before, but the following example
from Wikipedia is fontified differently if the ... is removed from before the
`args`. In that case args is fontified with `font-lock-variable-name-face`.
template<typename... Args> inline void expand(Args&&... args) {
pass( some_function(args)... );
}
FWIW, I've seen similar mis-fontifications before (without ...) and it hasn't
bothered me too much. I just found a reproducible case, so I guess I'll
open a bug for it.
Thanks for working on this. The raw string support is awesome!
-Ivan
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Thu, 30 Jun 2016 14:37:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 23610 <at> debbugs.gnu.org (full text, mbox):
Hello, Ivan.
On Wed, Jun 22, 2016 at 09:22:01AM -0600, Ivan Andrus wrote:
> On Sun, Jun 19, 2016 at 3:14 PM, Alan Mackenzie <acm <at> muc.de> wrote:
> > In article <mailman.202.1464109329.1216.bug-gnu-emacs <at> gnu.org> you wrote:
> >> Starting with emacs -Q, Y is not fontified in the snippet below, whereas
> >> X is.
> >> -Ivan
> >> template <typename X, typename... Y>
> >> class bob {
> >> };
> > [ .... ]
> > The following patch is a first attempt to fontify parameter packs. After
> > applying it, please be sure either to recompile CC Mode entirely, or
> > first to compile cc-langs.el (which contains macros), and then all three
> > of cc-fonts.el, cc-engine.el, and cc-mode.el.
> > It seems to fontify the "Y" above OK. I've tried it on a stock example
> > out of Wikipedia, and that works. Could you try it out on your code,
> > please, and let me know how well it works.
> It looks pretty good. I didn't notice this before, but the following example
> from Wikipedia is fontified differently if the ... is removed from before the
> `args`. In that case args is fontified with `font-lock-variable-name-face`.
> template<typename... Args> inline void expand(Args&&... args) {
> pass( some_function(args)... );
> }
What is this "&&" operator? It cannot be a logical and, and doesn't look
like anything to do with a move constructor. I've tried, and failed, to
find an explanation in http://en.cppreference.com/w/cpp/language. I
didn't find and explanation in the article "variadic templates" in
wikipedia either. A pointer to a web page explaining it would be much
appreciated.
I'm tempted to commit the patch as it is at the moment, but feel I ought
to understand this "&&" first.
> FWIW, I've seen similar mis-fontifications before (without ...) and it hasn't
> bothered me too much. I just found a reproducible case, so I guess I'll
> open a bug for it.
> Thanks for working on this. The raw string support is awesome!
Thanks! There've recently been one or two bugs fixed for raw string
support. The corrections are in the Emacs master branch.
> -Ivan
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Thu, 30 Jun 2016 15:11:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 23610 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Thu, Jun 30, 2016 at 10:36 AM, Alan Mackenzie <acm <at> muc.de> wrote:
> What is this "&&" operator?
It is an "rvalue reference".
/john
--
John Yates
109 Chandler St, #1
Boston, MA 02116
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Thu, 30 Jun 2016 16:48:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 23610 <at> debbugs.gnu.org (full text, mbox):
Hello, John.
On Thu, Jun 30, 2016 at 11:10:13AM -0400, John Yates wrote:
> On Thu, Jun 30, 2016 at 10:36 AM, Alan Mackenzie <acm <at> muc.de> wrote:
> > What is this "&&" operator?
> It is an "rvalue reference".
Thanks, that's exactly what I needed to know. I've now got these
"Args&&... args" expressions fontifying.
> /john
> --
> John Yates
> 109 Chandler St, #1
> Boston, MA 02116
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#23610
; Package
emacs,cc-mode
.
(Thu, 30 Jun 2016 17:25:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 23610 <at> debbugs.gnu.org (full text, mbox):
Hello again, Ivan.
On Wed, Jun 22, 2016 at 09:22:01AM -0600, Ivan Andrus wrote:
> On Sun, Jun 19, 2016 at 3:14 PM, Alan Mackenzie <acm <at> muc.de> wrote:
> > Hello, Ivan.
> > In article <mailman.202.1464109329.1216.bug-gnu-emacs <at> gnu.org> you wrote:
> >> Starting with emacs -Q, Y is not fontified in the snippet below, whereas
> >> X is.
> >> -Ivan
> >> template <typename X, typename... Y>
> >> class bob {
> >> };
> > [ .... ]
> > The following patch is a first attempt to fontify parameter packs. After
> > applying it, please be sure either to recompile CC Mode entirely, or
> > first to compile cc-langs.el (which contains macros), and then all three
> > of cc-fonts.el, cc-engine.el, and cc-mode.el.
> > It seems to fontify the "Y" above OK. I've tried it on a stock example
> > out of Wikipedia, and that works. Could you try it out on your code,
> > please, and let me know how well it works.
> It looks pretty good. I didn't notice this before, but the following example
> from Wikipedia is fontified differently if the ... is removed from before the
> `args`. In that case args is fontified with `font-lock-variable-name-face`.
> template<typename... Args> inline void expand(Args&&... args) {
> pass( some_function(args)... );
> }
OK. I think the patch below fixes it. Please try it out and report
back. (Same instructions about recompilation of CC Mode as last time
apply, since further macros in cc-langs.el have been modified). Please
note that the patch below is complete in itself, it isn't incremental,
based on the last patch. It's based on a current Emacs master branch.
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 48b9e5e..cc60175 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -7090,6 +7090,9 @@ c-forward-type
(while (cond
((looking-at c-decl-hangon-key)
(c-forward-keyword-clause 1))
+ ((looking-at c-pack-key)
+ (goto-char (match-end 1))
+ (c-forward-syntactic-ws))
((and c-opt-cpp-prefix
(looking-at c-noise-macro-with-parens-name-re))
(c-forward-noise-clause))))
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 4d36684..b903190 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1329,6 +1329,14 @@ 'c-opt-op-identitier-prefix
(c-lang-defvar c-stmt-delim-chars-with-comma
(c-lang-const c-stmt-delim-chars-with-comma))
+(c-lang-defconst c-pack-ops
+ "Ops which signal C++11's \"parameter pack\""
+ t nil
+ c++ '("..."))
+(c-lang-defconst c-pack-key
+ t (c-make-keywords-re 'appendable (c-lang-const c-pack-ops)))
+(c-lang-defvar c-pack-key (c-lang-const c-pack-key))
+
(c-lang-defconst c-auto-ops
;; Ops which signal C++11's new auto uses.
t nil
@@ -2958,6 +2966,10 @@ 'c-opt-op-identitier-prefix
"\\)"
"\\([^=]\\|$\\)")
c++ (concat "\\("
+ "&&"
+ "\\|"
+ "\\.\\.\\."
+ "\\|"
"[*(&]"
"\\|"
(c-lang-const c-type-decl-prefix-key)
> -Ivan
--
Alan Mackenzie (Nuremberg, Germany).
Reply sent
to
Alan Mackenzie <acm <at> muc.de>
:
You have taken responsibility.
(Sat, 23 Jul 2016 15:14:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Ivan Andrus <darthandrus <at> gmail.com>
:
bug acknowledged by developer.
(Sat, 23 Jul 2016 15:14:02 GMT)
Full text and
rfc822 format available.
Message #37 received at 23610-done <at> debbugs.gnu.org (full text, mbox):
Bug fixed in master.
--
Alan Mackenzie (Nuremberg, Germany).
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 21 Aug 2016 11:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 8 years and 307 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.