D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5216 - /+ parsed incorrectly in comments
Summary: /+ parsed incorrectly in comments
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Linux
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-14 04:04 UTC by Jonathan M Davis
Modified: 2015-06-09 01:31 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2010-11-14 04:04:26 UTC
This fails to compile

void main()
{
    /+
    // /+
    +/
}


giving this error

test.d(7): unterminated /+ +/ comment
test.d(7): found 'EOF' when expecting '}' following compound statement


It seems to be fine if it's not within a /+ +/ block, but once it is, the // comment is ignored, and since /+ is intended for commenting out code rather than just comments, this is not good behavior. All /+ and +/ should be ignored on lines where they are after //.
Comment 1 Walter Bright 2010-11-16 16:53:36 UTC
Commenting out code should properly be done using:

   version (none)
   {
   }

The only thing the /+ comments recognize are +/ and /+. They are working as designed. They are not intended to recognize tokens or other comments.
Comment 2 Jonathan M Davis 2010-11-16 17:24:07 UTC
I could have sworn that the online docs said that one of the main reasons for /+ +/ was to comment out code, but regardless, it's not like you usually run into /+ or +/ inside of comments instead of delimiting them. I only ran into it because I was working on the D lexer for Phobos and one of the comments had them in it. The main issue is that they work as designed, so if this was as intended, then that's fine.
Comment 3 nfxjfg 2010-11-16 19:08:20 UTC
(In reply to comment #1)
> Commenting out code should properly be done using:
> 
>    version (none)
>    {
>    }
> 
> The only thing the /+ comments recognize are +/ and /+. They are working as
> designed. They are not intended to recognize tokens or other comments.

That's unintuitive and error prone. Also you can't stick version anywhere. Obviously the design should be fixed.

Reopening as enhancement request.
Comment 4 bearophile_hugs 2010-11-16 19:46:48 UTC
(In reply to comment #3)
> (In reply to comment #1)
> > Commenting out code should properly be done using:
> > 
> >    version (none)
> >    {
> >    }
> > 
> > The only thing the /+ comments recognize are +/ and /+. They are working as
> > designed. They are not intended to recognize tokens or other comments.
> 
> That's unintuitive and error prone. Also you can't stick version anywhere.
> Obviously the design should be fixed.
> 
> Reopening as enhancement request.

Be more gentle. The current behaviour is not obviously bad.
Comment 5 Walter Bright 2010-11-17 01:08:25 UTC
>That's unintuitive and error prone.

I presume you mean the version(none). Unusual, yes. Unintuitive? How so? It's documented. Error prone? I don't see how - there's no way to set "none" as a version identifier.

>Also you can't stick version anywhere.

It's not necessary to stick it anywhere. It works fine for large blocks of code. For parts of an expression, /* */ works fine. It's hard to see an issue about this.

>Obviously the design should be fixed.

I don't think it's obvious wrong at all. It follows a simple rule, which I believe is better than having an arbitrarily complex rule with hard to remember special cases. Furthermore, if you do make a mistake with the /+ +/ nesting, you get an inevitable compiler error message.

And lastly, the current behavior has existed for 10 years and this is the first anyone has complained about it. Changing it would arbitrarily break existing code and hence annoy people for a rather dubious benefit.