From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#28418: 25.2; c++ angle bracket incorrect mismatch Date: Mon, 11 Sep 2017 21:15:43 +0000 Message-ID: <20170911211543.GD3605@ACM> References: <20170911175508.91132.qmail@mail.muc.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1505164953 26765 195.159.176.226 (11 Sep 2017 21:22:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 11 Sep 2017 21:22:33 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: 28418@debbugs.gnu.org To: "Tanis, Craig" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 11 23:22:29 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drW9e-0005gH-CF for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Sep 2017 23:22:06 +0200 Original-Received: from localhost ([::1]:60664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drW9l-0006Nv-Lv for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Sep 2017 17:22:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drW9e-0006Jd-4X for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 17:22:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drW9a-0008CA-5v for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 17:22:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1drW9a-0008Bp-1q; Mon, 11 Sep 2017 17:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1drW9Z-0006QM-MT; Mon, 11 Sep 2017 17:22:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Mon, 11 Sep 2017 21:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28418 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 28418-submit@debbugs.gnu.org id=B28418.150516486324625 (code B ref 28418); Mon, 11 Sep 2017 21:22:01 +0000 Original-Received: (at 28418) by debbugs.gnu.org; 11 Sep 2017 21:21:03 +0000 Original-Received: from localhost ([127.0.0.1]:34199 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drW8d-0006P7-FD for submit@debbugs.gnu.org; Mon, 11 Sep 2017 17:21:03 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:31119 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1drW8b-0006OK-Hp for 28418@debbugs.gnu.org; Mon, 11 Sep 2017 17:21:02 -0400 Original-Received: (qmail 44792 invoked by uid 3782); 11 Sep 2017 21:20:56 -0000 Original-Received: from acm.muc.de (p548C7BC7.dip0.t-ipconnect.de [84.140.123.199]) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 11 Sep 2017 23:20:55 +0200 Original-Received: (qmail 5328 invoked by uid 1000); 11 Sep 2017 21:15:43 -0000 Content-Disposition: inline In-Reply-To: <20170911175508.91132.qmail@mail.muc.de> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:136812 Archived-At: Hello again, Craig. On Mon, Sep 11, 2017 at 17:55:08 -0000, Alan Mackenzie wrote: > In article 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))))) ;; 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