www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24251] New: Spurious forward reference error with nested struct

https://issues.dlang.org/show_bug.cgi?id=24251

          Issue ID: 24251
           Summary: Spurious forward reference error with nested struct
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andy.pj.hanson gmail.com

```
struct A {
        B b;
}

struct B {
        struct Inner {
                C c;
        }
}

struct C {
        A a;
}
```

This results in the error:
```
a.d(12): Error: struct `a.A` no size because of forward reference
```

There's no need for this error, since an instance of B doesn't actually contain
a C.
Just like there is no error in this simpler case:

```
struct A {
        struct Inner {
                B b;
        }
}

struct B {
        A a;
}
```

I discovered this when chasing a sporadic forward reference error that appeared
when changing unrelated code.

--
Nov 19 2023