Bug 23697 – No examples of invalid forward references in C code accepted by ImportC

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2023-02-12T15:20:25Z
Last change time
2023-06-01T19:26:00Z
Keywords
accepts-invalid, ImportC, pull
Assigned to
No Owner
Creator
Iain Buclaw
Depends on
23689
See also
https://issues.dlang.org/show_bug.cgi?id=23689

Comments

Comment #0 by ibuclaw — 2023-02-12T15:20:25Z
When compiling the test with `gcc -std=c11 -fsyntax-only` compilable/test22705.c:4:1: error: unknown type name ‘Ta’ 4 | Ta *pa; | ^~ compilable/test22705.c:8:1: error: unknown type name ‘Tb’; did you mean ‘Ta’? 8 | Tb *pb; | ^~ | Ta Original test content: ``` Ta *pa; struct Sa { int x; }; typedef struct Sa Ta; Tb *pb; struct Sb; typedef struct Sb { int x; } Tb; ```
Comment #1 by bugzilla — 2023-02-20T06:56:45Z
ImportC, as an extension, allows forward referencing. As it relies on D for the semantic analysis, this is natural. It doesn't cause any harm, though. I recommend gcc just ignore this test.
Comment #2 by ibuclaw — 2023-02-20T11:01:11Z
(In reply to Walter Bright from comment #1) > ImportC, as an extension, allows forward referencing. As it relies on D for > the semantic analysis, this is natural. It doesn't cause any harm, though. > > I recommend gcc just ignore this test. The point is just to identify where we're deviating from standard C. Because if we're not testing ImportC against actual C code, how can we call it a C compiler? I think having an example of such forward reference on the documentation page would be enough to satisfy this isssue: https://dlang.org/spec/importc.html#forward-references Just give friendly names to the first example in this issue. ``` Ta *pa; struct Sa { int x; }; typedef struct Sa Ta; ```
Comment #3 by ibuclaw — 2023-02-20T12:37:09Z
*** Issue 23720 has been marked as a duplicate of this issue. ***
Comment #4 by ibuclaw — 2023-02-20T12:38:58Z
Another example of forward reference code that is accepted by ImportC, rejected by standard C. ``` struct S s; int* p = &s.t.x; struct S { int a; struct T t; }; ``` Giving both as examples on the ImportC documentation page would be good enough.
Comment #5 by ibuclaw — 2023-02-20T12:40:13Z
*** Issue 23721 has been marked as a duplicate of this issue. ***
Comment #6 by ibuclaw — 2023-02-20T12:41:46Z
Missing definition of `T` in second example: ``` struct S s; int* p = &s.t.x; struct S { int a; struct T t; }; struct T { int b; int x; }; ```
Comment #7 by dlang-bot — 2023-06-01T07:04:53Z
@WalterBright created dlang/dlang.org pull request #3624 "fix Issue 23697 - No examples of invalid forward references in C code…" fixing this issue: - fix Issue 23697 - No examples of invalid forward references in C code accepted by ImportC https://github.com/dlang/dlang.org/pull/3624
Comment #8 by dlang-bot — 2023-06-01T19:26:00Z
dlang/dlang.org pull request #3624 "fix Issue 23697 - No examples of invalid forward references in C code…" was merged into master: - 4c93445c1338b808478afd521a2ef335e045d951 by Walter Bright: fix Issue 23697 - No examples of invalid forward references in C code accepted by ImportC https://github.com/dlang/dlang.org/pull/3624