From: Alan Mackenzie <acm@muc.de>
To: "Tanis, Craig" <Craig-Tanis@utc.edu>
Cc: 28418@debbugs.gnu.org
Subject: bug#28418: 25.2; c++ angle bracket incorrect mismatch
Date: Mon, 11 Sep 2017 21:15:43 +0000 [thread overview]
Message-ID: <20170911211543.GD3605@ACM> (raw)
In-Reply-To: <20170911175508.91132.qmail@mail.muc.de>
Hello again, Craig.
On Mon, Sep 11, 2017 at 17:55:08 -0000, Alan Mackenzie wrote:
> In article <mailman.329.1505143569.14750.bug-gnu-emacs@gnu.org> you wrote:
> > The opening angle bracket from the stream insertion operator (<<)
> > becomes misclassified as an opening delimiter if a later string literal in the
> > file contains >>
> Firstly, thanks for taking the trouble to report this bug, and thanks
> even more for trimming it down to a nice, easy to work with snippet.
> > See the following sample file. Notice that you must type in the string
> > as indicated because the act of typing triggers the misclassification.
> > When the error occurs, the closing bracket matches the '<' right before "nice".
> Being more precise, I think the >> in the string already has to exist at
> the time the << gets typed.
> > I suggest pasting this into a new file and then manipulating the first string.
> > //---------------------------
> > int main(int argc, char *argv[])
> > {
> > std::cout << "nice"; // <-- manually type in this string
> > return 0;
> > }
> > void subroutine()
> > {
> > char* foo= "a >> b";
> > return;
> > }
> > //---------------------------
> What seems to be happening is after typing in the opening " of "nice",
> but before typing in the closing ", we have a sort of string extending
> from that opening " to the opening " of "a >> b". That >> is
> (temporarily) outside a string, and is thus balanced with the <<. This
> balancing is done by applying a "text property" to each of the second <
> and the first > characters.
> Where things go wrong is when "nice" is closed by typing the closing ".
> At this point, the text properties don't get removed from these < and >,
> although they no longer match. This is the fault in the code.
> Give me a little time, and I will fix it.
More precisely, the error was allowing those two characters to be
matched in the first place. This happened when trying to parse a < .. >
construct starting at the <<, which fails, since the << is not a
template delimiter. The bug was then to move a single character
forward, then search for the next < (which is finds without moving).
Now it manages spuriously to parse the < .. >, and matches the < and the
>. The solution is instead to move a whole token forward.
The following patch should fix this. Please apply this to your Emacs
(cc-engine.el is in directory ..../emacs/lisp/progmodes) and recompile
cc-engine.el. Please then check that the bug is fixed properly in your
real code, and let me know how it goes.
(If you want any help in applying the patch, or byte-compiling
cc-engine.el, feel free to contact me by private email.)
Here's the patch:
diff -r d0ed864dd852 cc-engine.el
--- a/cc-engine.el Sun Sep 03 10:33:57 2017 +0000
+++ b/cc-engine.el Mon Sep 11 21:02:25 2017 +0000
@@ -6431,7 +6431,7 @@
(not (eq (c-get-char-property (point) 'c-type)
'c-decl-arg-start)))))))
(or (c-forward-<>-arglist nil)
- (forward-char)))))
+ (c-forward-token-2)))))
\f
;; Functions to handle C++ raw strings.
> > ----
> > Craig Tanis, PhD
> > UTC Computer Science and Engineering
> > craig-tanis@utc.edu
--
Alan Mackenzie (Nuremberg, Germany).
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
next prev parent reply other threads:[~2017-09-11 21:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-11 14:49 bug#28418: 25.2; c++ angle bracket incorrect mismatch Tanis, Craig
[not found] ` <mailman.329.1505143569.14750.bug-gnu-emacs@gnu.org>
2017-09-11 17:55 ` Alan Mackenzie
[not found] ` <20170911175508.91132.qmail@mail.muc.de>
2017-09-11 21:15 ` Alan Mackenzie [this message]
[not found] ` <47D29868-55CE-475C-8827-0BBC60621D75@utc.edu>
2017-09-12 17:07 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170911211543.GD3605@ACM \
--to=acm@muc.de \
--cc=28418@debbugs.gnu.org \
--cc=Craig-Tanis@utc.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).