[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escape
From: |
Michael Welsh Duggan |
Subject: |
bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped. |
Date: |
Thu, 24 Sep 2020 16:27:48 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
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)
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped., (continued)
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped., Alan Mackenzie, 2020/09/23
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped., Alan Mackenzie, 2020/09/24
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped., Stefan Monnier, 2020/09/24
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped., Alan Mackenzie, 2020/09/24
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped., Stefan Monnier, 2020/09/24
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped., Michael Welsh Duggan, 2020/09/24
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped., Alan Mackenzie, 2020/09/24
- bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped.,
Michael Welsh Duggan <=