GNU bug report logs - #50640
28.0.50; incorrect highlighting in C++ mode

Previous Next

Package: emacs;

Reported by: Vincent Lefevre <vincent <at> vinc17.net>

Date: Fri, 17 Sep 2021 12:59:02 UTC

Severity: minor

Tags: wontfix

Found in version 28.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

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 50640 in the body.
You can then email your comments to 50640 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#50640; Package emacs. (Fri, 17 Sep 2021 12:59:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Vincent Lefevre <vincent <at> vinc17.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 17 Sep 2021 12:59:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Vincent Lefevre <vincent <at> vinc17.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; incorrect highlighting in C++ mode
Date: Fri, 17 Sep 2021 14:57:31 +0200
Consider a test.cc file containing:

  if (xMin - xt < t3Font->glyphX ||
      yMin - yt < t3Font->glyphY ||
      xMax - xt > t3Font->glyphX + t3Font->glyphW ||
      yMax - yt > t3Font->glyphY + t3Font->glyphH) {
  }

(this comes from the xpdf source) and open it with "emacs -Q".

The first two "xt" and "yt" are highlighted in green instead of
remaining in black. If I remove the last condition as follows
and reopen the file:

  if (xMin - xt < t3Font->glyphX ||
      yMin - yt < t3Font->glyphY ||
      xMax - xt > t3Font->glyphX + t3Font->glyphW) {
  }

then only the "yt" is highlighted incorrectly.


In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0)
 of 2021-09-17 built on zira
Repository revision: 8220df9355e105459e91623dd63f7a08a08cfe09
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux bookworm/sid

Configured using:
 'configure --prefix=/home/vinc17/opt/emacs-master'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LC_COLLATE: POSIX
  value of $LC_CTYPE: C.UTF-8
  value of $LC_TIME: en_DK.utf8
  value of $LANG: POSIX
  locale-coding-system: utf-8-unix

Major mode: C++//l

Minor modes in effect:
  display-time-mode: t
  show-paren-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-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
  column-number-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  abbrev-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr warnings emacsbug message rmc puny dired
dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068 epg-config
gnus-util rmail rmail-loaddefs auth-source cl-seq eieio eieio-core
cl-macs eieio-loaddefs password-cache json map text-property-search
time-date subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
cc-mode cc-fonts cc-guess cc-menus cc-cmds time cus-load paren cc-styles
cc-align cc-engine cc-vars cc-defs edmacro kmacro cl-loaddefs cl-lib
iso-transl tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer 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 composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 80328 6010)
 (symbols 48 9599 1)
 (strings 32 26386 987)
 (string-bytes 1 979203)
 (vectors 16 13517)
 (vector-slots 8 174949 9740)
 (floats 8 28 46)
 (intervals 56 237 0)
 (buffers 992 12))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50640; Package emacs. (Sat, 25 Sep 2021 18:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 50640 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 50640 <at> debbugs.gnu.org, Vincent Lefevre <vincent <at> vinc17.net>
Subject: Re: bug#50640: 28.0.50; incorrect highlighting in C++ mode
Date: Sat, 25 Sep 2021 11:17:07 -0700
Vincent Lefevre <vincent <at> vinc17.net> writes:

> Consider a test.cc file containing:
>
>   if (xMin - xt < t3Font->glyphX ||
>       yMin - yt < t3Font->glyphY ||
>       xMax - xt > t3Font->glyphX + t3Font->glyphW ||
>       yMax - yt > t3Font->glyphY + t3Font->glyphH) {
>   }
>
> (this comes from the xpdf source) and open it with "emacs -Q".
>
> The first two "xt" and "yt" are highlighted in green instead of
> remaining in black. If I remove the last condition as follows
> and reopen the file:
>
>   if (xMin - xt < t3Font->glyphX ||
>       yMin - yt < t3Font->glyphY ||
>       xMax - xt > t3Font->glyphX + t3Font->glyphW) {
>   }
>
> then only the "yt" is highlighted incorrectly.

Alan, could you take a look at this bug report?

(I don't know if you're subscribed to the bug list, my apologies if you
have already seen it.)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50640; Package emacs. (Sat, 25 Sep 2021 21:18:02 GMT) Full text and rfc822 format available.

Message #11 received at 50640 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Stefan Kangas <stefan <at> marxist.se>, Vincent Lefevre <vincent <at> vinc17.net>
Cc: 50640 <at> debbugs.gnu.org
Subject: Re: bug#50640: 28.0.50; incorrect highlighting in C++ mode
Date: Sat, 25 Sep 2021 21:17:06 +0000
Hello, Vincent and Stefan.

On Sat, Sep 25, 2021 at 11:17:07 -0700, Stefan Kangas wrote:
> Vincent Lefevre <vincent <at> vinc17.net> writes:

> > Consider a test.cc file containing:

> >   if (xMin - xt < t3Font->glyphX ||
> >       yMin - yt < t3Font->glyphY ||
> >       xMax - xt > t3Font->glyphX + t3Font->glyphW ||
> >       yMax - yt > t3Font->glyphY + t3Font->glyphH) {
> >   }

> > (this comes from the xpdf source) and open it with "emacs -Q".

> > The first two "xt" and "yt" are highlighted in green instead of
> > remaining in black.

Yes.  C++ Mode is recognising the < .. < .. > .. > as two nested
templates.  The green is font-lock-type-face.  :-(

> > If I remove the last condition as follows and reopen the file:

> >   if (xMin - xt < t3Font->glyphX ||
> >       yMin - yt < t3Font->glyphY ||
> >       xMax - xt > t3Font->glyphX + t3Font->glyphW) {
> >   }

> > then only the "yt" is highlighted incorrectly.

Yes, then only yt opens a "template", there being no closing > to balance
the xt <.

There's really not much which can be done about this in CC Mode, sorry.
CC Mode's analysis of ambiguous C++ constructs is not very deep, so it
sometimes gets it wrong, as here.

I would be in favour of closing this bug as "won't fix" (actually, can't
fix).

There's an intention in the medium future to introduce rigorous analyses
of source code into Emacs with a language server protocol program called
"Tree Sitter".  That should solve problems like this one.

In the meantime, a workaround would be to change the order of the terms
in that expression so that the <s come after the >s rather than before
them, if you have control of the source code.

> Alan, could you take a look at this bug report?

> (I don't know if you're subscribed to the bug list, my apologies if you
> have already seen it.)

I'm not actually subscribed to the bug list.  I'd have trouble coping
with the volume of posts there.  I try to skim over the archive on the
web every week or so, to try not to miss anything.  So thanks, Stefan,
for the heads up!

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50640; Package emacs. (Sat, 25 Sep 2021 21:52:02 GMT) Full text and rfc822 format available.

Message #14 received at 50640 <at> debbugs.gnu.org (full text, mbox):

From: Vincent Lefevre <vincent <at> vinc17.net>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 50640 <at> debbugs.gnu.org, Stefan Kangas <stefan <at> marxist.se>
Subject: Re: bug#50640: 28.0.50; incorrect highlighting in C++ mode
Date: Sat, 25 Sep 2021 23:51:17 +0200
On 2021-09-25 21:17:06 +0000, Alan Mackenzie wrote:
> Hello, Vincent and Stefan.
> 
> On Sat, Sep 25, 2021 at 11:17:07 -0700, Stefan Kangas wrote:
> > Vincent Lefevre <vincent <at> vinc17.net> writes:
> 
> > > Consider a test.cc file containing:
> 
> > >   if (xMin - xt < t3Font->glyphX ||
> > >       yMin - yt < t3Font->glyphY ||
> > >       xMax - xt > t3Font->glyphX + t3Font->glyphW ||
> > >       yMax - yt > t3Font->glyphY + t3Font->glyphH) {
> > >   }
> 
> > > (this comes from the xpdf source) and open it with "emacs -Q".
> 
> > > The first two "xt" and "yt" are highlighted in green instead of
> > > remaining in black.
> 
> Yes.  C++ Mode is recognising the < .. < .. > .. > as two nested
> templates.  The green is font-lock-type-face.  :-(
> 
> > > If I remove the last condition as follows and reopen the file:
> 
> > >   if (xMin - xt < t3Font->glyphX ||
> > >       yMin - yt < t3Font->glyphY ||
> > >       xMax - xt > t3Font->glyphX + t3Font->glyphW) {
> > >   }
> 
> > > then only the "yt" is highlighted incorrectly.
> 
> Yes, then only yt opens a "template", there being no closing > to balance
> the xt <.
> 
> There's really not much which can be done about this in CC Mode, sorry.
> CC Mode's analysis of ambiguous C++ constructs is not very deep, so it
> sometimes gets it wrong, as here.

Note that when < .. < .. > .. > comparisons occur, there is
probably || or && between them. Are C++ nested templates common
with || or && inside them? If not, || and && should be forbidden
in nested template matching.

Alternatively, whitespace characters could also give a hint:
AFAIK, for templates, this is usually no whitespace after '<'
and no whitespace before '>'.

-- 
Vincent Lefèvre <vincent <at> vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




Severity set to 'minor' from 'normal' Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Wed, 29 Sep 2021 15:21:04 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50640; Package emacs. (Fri, 26 Aug 2022 11:43:01 GMT) Full text and rfc822 format available.

Message #19 received at 50640 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 50640 <at> debbugs.gnu.org, Vincent Lefevre <vincent <at> vinc17.net>,
 Stefan Kangas <stefan <at> marxist.se>
Subject: Re: bug#50640: 28.0.50; incorrect highlighting in C++ mode
Date: Fri, 26 Aug 2022 13:42:24 +0200
Alan Mackenzie <acm <at> muc.de> writes:

> There's really not much which can be done about this in CC Mode, sorry.
> CC Mode's analysis of ambiguous C++ constructs is not very deep, so it
> sometimes gets it wrong, as here.
>
> I would be in favour of closing this bug as "won't fix" (actually, can't
> fix).

OK; closing this as a "wontfix", then.




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 26 Aug 2022 11:43:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 50640 <at> debbugs.gnu.org and Vincent Lefevre <vincent <at> vinc17.net> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 26 Aug 2022 11:43:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50640; Package emacs. (Fri, 26 Aug 2022 12:25:01 GMT) Full text and rfc822 format available.

Message #26 received at 50640 <at> debbugs.gnu.org (full text, mbox):

From: Vincent Lefevre <vincent <at> vinc17.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 50640 <at> debbugs.gnu.org, Alan Mackenzie <acm <at> muc.de>,
 Stefan Kangas <stefan <at> marxist.se>
Subject: Re: bug#50640: 28.0.50; incorrect highlighting in C++ mode
Date: Fri, 26 Aug 2022 14:24:08 +0200
On 2022-08-26 13:42:24 +0200, Lars Ingebrigtsen wrote:
> Alan Mackenzie <acm <at> muc.de> writes:
> 
> > There's really not much which can be done about this in CC Mode, sorry.
> > CC Mode's analysis of ambiguous C++ constructs is not very deep, so it
> > sometimes gets it wrong, as here.
> >
> > I would be in favour of closing this bug as "won't fix" (actually, can't
> > fix).
> 
> OK; closing this as a "wontfix", then.

Isn't it really possible to have an option to forbid && and ||
in <...> constructs?

I think that this would be useful in practice, because when && or ||
is involved, < and > around them probably mean comparisons.

Note that the issue is more general than nested < .. < .. > .. >.
Bad highlighting also occurs just with "a < b || c > d".

-- 
Vincent Lefèvre <vincent <at> vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 24 Sep 2022 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 280 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.