Bug 23407 – ImportC: function-local struct definition as part of variable declaration doesn’t shadow global definition
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-10-12T05:11:20Z
Last change time
2023-01-12T12:46:32Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
dave287091
Comments
Comment #0 by dave287091 — 2022-10-12T05:11:20Z
I’m not sure if the summary is the right way to say it, but the following C program fails a static assertion. Without the declaration at global scope it succeeds.
struct Foo {
int x;
};
_Static_assert(sizeof(struct Foo) == sizeof(int), "");
void one(void){
struct Foo {
int y, z;
};
struct Foo f = {0};
_Static_assert(sizeof(struct Foo) == 2*sizeof(int), "");
struct Foo* pf = &f;
pf->y = pf->z;
}
void two(void){
struct Foo {
int y, z;
} f = {0};
_Static_assert(sizeof(f) == 2*sizeof(int), "");
_Static_assert(sizeof(struct Foo) == 2*sizeof(int), ""); // fails
// if you comment out the above assertion, then you get the error below
struct Foo* pf = &f;
pf->y = pf->z; // Error `y` is not a member of `Foo`.
}
Comment #1 by dlang-bot — 2023-01-12T07:54:21Z
@WalterBright created dlang/dmd pull request #14806 "fix Issue 23407 - ImportC: function-local struct definition as part o…" fixing this issue:
- fix Issue 23407 - ImportC: function-local struct definition as part of variable declaration doesn.t shadow global definition
https://github.com/dlang/dmd/pull/14806
Comment #2 by dlang-bot — 2023-01-12T12:46:32Z
dlang/dmd pull request #14806 "fix Issue 23407 - ImportC: function-local struct definition as part o…" was merged into master:
- 922c7b18c88ec3f6ad864d66867eb228838e2523 by Walter Bright:
fix Issue 23407 - ImportC: function-local struct definition as part of variable declaration doesn.t shadow global definition
https://github.com/dlang/dmd/pull/14806