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.

Full log


View this message in rfc822 format

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




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

Previous Next


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