D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23407 - ImportC: function-local struct definition as part of variable declaration doesn’t shadow global definition
Summary: ImportC: function-local struct definition as part of variable declaration doe...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: ImportC, pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2022-10-12 05:11 UTC by dave287091
Modified: 2023-01-12 12:46 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description dave287091 2022-10-12 05:11:20 UTC
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 Dlang Bot 2023-01-12 07:54:21 UTC
@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 Dlang Bot 2023-01-12 12:46:32 UTC
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