Bug 23883 – `#line` is off by one and off by two if a line comment follows

Status
NEW
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-05-04T11:32:25Z
Last change time
2024-12-13T19:28:30Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#20267 →

Comments

Comment #0 by qs.il.paperinik — 2023-05-04T11:32:25Z
```d #line 3 "a.d" ``` and ```d #line 3 "a.d" // ``` behave differently: In the first case, the #line is line 2, in the second case, the #line is line 1. I created https://github.com/dlang/dlang.org/pull/3601 to document the current behavior in the non-comment case.
Comment #1 by razvan.nitu1305 — 2023-05-05T09:01:11Z
The #line directive needs to be terminated by a newline or EOF. In your example the newline is commented, therefore whatever comes next after the comment on the exact following line has to be a newline or EOF so that the directive is correctly lexed. I think that the best way to proceed here is to add a spec mention about this as fixing will add unnecessary complexity (checking for comments before the directive ends) to support an unlikely corner case.
Comment #2 by qs.il.paperinik — 2023-05-09T15:40:34Z
So, you’re suggesting that we make a bug a feature. Checking for comments before the directive ends isn’t that big of a deal. You don’t even have to handle it correctly, you can make it an error if that is easier. It’s surprising, and you shouldn’t surprise users.
Comment #3 by razvan.nitu1305 — 2023-05-11T13:57:31Z
(In reply to Bolpat from comment #2) > So, you’re suggesting that we make a bug a feature. Checking for comments > before the directive ends isn’t that big of a deal. > No, I am saying that this is such niche case (why would you attach comments to line directives?) that it doesn't really warrant the complexity added in the lexer. But I understand your point of view, that's why I'm leaving this bug report open. > You don’t even have to handle it correctly, you can make it an error if that > is easier. It’s surprising, and you shouldn’t surprise users.
Comment #4 by robert.schadek — 2024-12-13T19:28:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20267 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB