unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Welsh Duggan <mwd@cert.org>
To: Alan Mackenzie <acm@muc.de>
Cc: "Michael Welsh Duggan" <mwd@md5i.com>,
	"Mattias Engdegård" <mattiase@acm.org>,
	"43558@debbugs.gnu.org" <43558@debbugs.gnu.org>,
	"Stefan Monnier" <monnier@iro.umontreal.ca>
Subject: bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped.
Date: Thu, 24 Sep 2020 16:27:48 -0400	[thread overview]
Message-ID: <y2tdefr1qqc43f.fsf@lx-birch.ad.sei.cmu.edu> (raw)
In-Reply-To: <20200924195742.GC4714@ACM> (Alan Mackenzie's message of "Thu, 24 Sep 2020 15:57:42 -0400")

Alan Mackenzie <acm@muc.de> writes:

> Hello, Michael.
>
> On Thu, Sep 24, 2020 at 14:52:16 -0400, Michael Welsh Duggan wrote:
>> Alan Mackenzie <acm@muc.de> writes:
>
>> > On Wed, Sep 23, 2020 at 11:01:59 +0200, Mattias Engdegård wrote:
>> >> Sorry if I misunderstood, but since when do backslashes escape */ in C?
>
>> > Since forever, but only in the CC Mode test suite.  :-(
>
>> > I just tried it out with gcc, and it seems that \*/ does indeed end a
>> > block comment.  But an escaped newline doesn't end a line comment,
>> > instead continuing it to the next line.  So I got confused.  Thanks for
>> > pointing out the mistake.
>
>> > It seems that as well as the existing variable
>> > comment-end-can-be-escaped, we need a new one, say
>> > line-comment-end-can-be-escaped, too.  In C and C++ modes, these would
>> > be nil and t respectively.
>
>> But where does it say that backslashes escape */ in C++?
>
> Nowhere.  :-(
>
> There has been a test in the CC Mode test suite for many years which
> assumed this (but was disabled for existing (X)Emacs versions, waiting
> for a new Emacs version to be "fixed").
>
>> The C++ 14 standard (and it hasn't changed through C++ 20) says:
>
>>     2.7 Comments [lex.comment]
>     
>>     The characters /* start a comment, which terminates with the
>>     characters */. These comments do not nest.  The characters // start
>>     a comment, which terminates immediately before the next new-line
>>     character.
>
> For all the difference it makes, Emacs assumes the comment ends _after_
> the NL.
>
>>     If there is a form-feed or a vertical-tab character in such a
>>     comment, only white-space characters shall appear between it and
>>     the new-line that terminates the comment; no diagnostic is
>>     required.
>
> I didn't know that.  Emacs/CC Mode doesn't code up this subtlety.  It
> probably isn't worth bothering about.
>
>>     [ Note: The comment characters //, /*, and */ have no special
>>     meaning within a // comment and are treated just like other
>>     characters. Similarly, the comment characters // and /* have no
>>     special meaning within a /* comment.  — end note ]
>
> Additionally, an escaped newline continues a comment onto the next line.
> This happens, notionally, at a very early stage of compilation where a
> backslash followed by NL anywhere get replaced by a space.  I think that
> even two backslashes followed by NL would get replaced by backslash,
> space.

Almost.  A backslash followed by a newline is elided completely, joining
the lines.  (Not replaced by a space.  Otherwise, I concur.

-- 
Michael Welsh Duggan
(mwd@cert.org)





      reply	other threads:[~2020-09-24 20:27 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22  9:35 bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped Alan Mackenzie
2020-09-22 14:09 ` Stefan Monnier
2020-09-22 19:41   ` Alan Mackenzie
     [not found] ` <handler.43558.B.160076736116422.ack@debbugs.gnu.org>
2020-09-23  8:57   ` Alan Mackenzie
2020-09-23  9:01 ` Mattias Engdegård
2020-09-23 14:48   ` Alan Mackenzie
2020-09-23 18:44     ` Stefan Monnier
2020-09-23 19:44       ` Alan Mackenzie
2020-09-23 20:02         ` Stefan Monnier
2020-09-24 10:20       ` Alan Mackenzie
2020-09-24 16:56         ` Stefan Monnier
2020-09-24 18:50           ` Alan Mackenzie
2020-09-24 22:43             ` Stefan Monnier
2020-11-19 21:18           ` Alan Mackenzie
2020-11-19 22:47             ` Stefan Monnier
2020-11-22 13:12               ` Alan Mackenzie
2020-11-22 15:20                 ` Stefan Monnier
2020-11-22 17:08                   ` Alan Mackenzie
2020-11-22 17:46                     ` Dmitry Gutov
2020-11-22 18:19                       ` Alan Mackenzie
2020-11-22 20:39                         ` Dmitry Gutov
2020-11-22 21:13                           ` Alan Mackenzie
2020-11-22 21:34                             ` Dmitry Gutov
2020-11-22 22:01                               ` Alan Mackenzie
2020-11-22 23:00                                 ` Stefan Monnier
2021-05-13 10:38                                   ` Lars Ingebrigtsen
2021-05-13 14:51                                     ` Alan Mackenzie
2021-05-16 13:53                                       ` Lars Ingebrigtsen
2022-04-28 11:17                                       ` Lars Ingebrigtsen
2022-04-28 18:52                                         ` Alan Mackenzie
2020-11-22 23:10                     ` Stefan Monnier
2020-11-22 15:35                 ` Eli Zaretskii
2020-11-22 17:03                   ` Alan Mackenzie
2020-09-24 18:52     ` Michael Welsh Duggan
2020-09-24 19:57       ` Alan Mackenzie
2020-09-24 20:27         ` Michael Welsh Duggan [this message]

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=y2tdefr1qqc43f.fsf@lx-birch.ad.sei.cmu.edu \
    --to=mwd@cert.org \
    --cc=43558@debbugs.gnu.org \
    --cc=acm@muc.de \
    --cc=mattiase@acm.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=mwd@md5i.com \
    /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).