D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22825 - #line parsing doesn't follow the spec
Summary: #line parsing doesn't follow the spec
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, ImportC, pull
Depends on:
Blocks:
 
Reported: 2022-02-26 10:11 UTC by Iain Buclaw
Modified: 2022-03-22 13:10 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Iain Buclaw 2022-02-26 10:11:33 UTC
Grammar is:

---
SpecialTokenSequence:
    # line IntegerLiteral Filespec(opt) EndOfLine
    # line __LINE__ Filespec(opt) EndOfLine
---

Because newlines (EndOfLine) is part of the grammar, then any other newlines found between `#` and `EndOfLine` should not be ignored when parsing them.

This does not apply to multi-line comments, and other such markers that are consumed and ignored by the lexer.

So while this should be accepted as valid code
---
#line /*
         multi-line comment
*/ 42
int var;
---

This should not compile, but currently does.
---
#line /*
         multi-line comment
*/ 
42
int var;
---

(There are similarities in this to issue 22812 for importC)
Comment 1 Iain Buclaw 2022-02-26 21:34:13 UTC
To be clearer, this compiles, probably shouldn't.
---
#
                 line




12
void main()
{
}
---
Comment 2 Dlang Bot 2022-02-27 10:25:09 UTC
@ibuclaw created dlang/dmd pull request #13727 "fix Issue 22825 - #line parsing doesn't follow the spec" fixing this issue:

- fix Issue 22825 - #line parsing doesn't follow the spec

https://github.com/dlang/dmd/pull/13727
Comment 3 Dlang Bot 2022-02-28 11:07:45 UTC
@ibuclaw created dlang/dlang.org pull request #3234 "Issue 22825: First newline terminates special token sequences" mentioning this issue:

- Issue 22825: First newline terminates special token sequences

https://github.com/dlang/dlang.org/pull/3234
Comment 4 Dlang Bot 2022-02-28 14:31:39 UTC
dlang/dlang.org pull request #3234 "Issue 22825: First newline terminates special token sequences" was merged into master:

- 92b9536d6307d3f48fd5634e3dc870ec63f8ed16 by Iain Buclaw:
  Issue 22825: First newline terminates special token sequences

https://github.com/dlang/dlang.org/pull/3234
Comment 5 Walter Bright 2022-03-02 21:47:15 UTC
Fix was merged.
Comment 6 Iain Buclaw 2022-03-03 18:23:42 UTC
Spec was merged, not the bug fix.
Comment 7 Dlang Bot 2022-03-18 17:23:11 UTC
@ibuclaw updated dlang/dmd pull request #13728 "fix Issue 22812 - ImportC: C11 does not allow newlines between the start and end of a directive" fixing this issue:

- fix Issue 22825 - #line parsing doesn't follow the spec

https://github.com/dlang/dmd/pull/13728
Comment 8 Dlang Bot 2022-03-22 13:10:06 UTC
dlang/dmd pull request #13728 "fix Issue 22812 - ImportC: C11 does not allow newlines between the start and end of a directive" was merged into master:

- dd708f0925e8daa70483422105201b5f02ee9829 by Iain Buclaw:
  fix Issue 22825 - #line parsing doesn't follow the spec

https://github.com/dlang/dmd/pull/13728