www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - =?UTF-8?B?W0lzc3VlIDIzNDA3XSBOZXc6IEltcG9ydEM6IGZ1bmN0aW9uLWxv?=


          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 puremagic.com
          Reporter: dave287091 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

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`.

Oct 11 2022