[Issue 23407] New: ImportC: function-local struct definition as part of variable declaration doesn’t shadow global definition
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 12 05:11:20 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23407
Issue ID: 23407
Summary: ImportC: function-local struct definition as part of
variable declaration doesn’t shadow global definition
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ImportC, rejects-valid
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dave287091 at gmail.com
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`.
}
--
More information about the Digitalmars-d-bugs
mailing list