D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22814 - ImportC: C11 lexer deletes escaped new lines during translation
Summary: ImportC: C11 lexer deletes escaped new lines during translation
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: ImportC, rejects-valid
Depends on:
Blocks:
 
Reported: 2022-02-22 18:51 UTC by Iain Buclaw
Modified: 2022-02-28 07:29 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-22 18:51:04 UTC
Following on from issue 22812, while new lines can't be ignored, they can however be escaped.

From C11 5.1.1.2-2:
---
Each instance of a backslash character ( \) immediately followed by a new-line
character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place.
---


So whilst issue 22812 is an error, this should be accepted as valid:
---
# \
    pragma \
pack \
    ( \
2 \
    )
struct S
{
    int i;
    short j;
    double k;
};
# \
    pragma \
pack \
    ( \
)
---
Comment 1 Walter Bright 2022-02-28 07:29:33 UTC
Backslash line splicing is done by the preprocessor, not the C compiler. (Try it, run the example code through cpp.)

So the ImportC lexer should never see the \, and this is not a bug in ImportC.