75 lines · cpp
1int main(int argc, char** argv)2{3 struct A {4 struct {5 int x = 1;6 };7 int y = 2;8 } a;9 10 struct B {11 // Anonymous struct inherits another struct.12 struct : public A {13 int z = 3;14 };15 int w = 4;16 A a;17 } b;18 19 // Anonymous classes and unions.20 struct C {21 union {22 int x = 5;23 };24 class {25 public:26 int y = 6;27 };28 } c;29 30 // Multiple levels of anonymous structs.31 struct D {32 struct {33 struct {34 int x = 7;35 struct {36 int y = 8;37 };38 };39 int z = 9;40 struct {41 int w = 10;42 };43 };44 } d;45 46 struct E {47 struct IsNotAnon {48 int x = 11;49 };50 } e;51 52 struct F {53 struct {54 int x = 12;55 } named_field;56 } f;57 58 // Inherited unnamed struct without an enclosing parent class.59 struct : public A {60 struct {61 int z = 13;62 };63 } unnamed_derived;64 65 struct DerivedB : public B {66 struct {67 // `w` in anonymous struct overrides `w` from `B`.68 int w = 14;69 int k = 15;70 };71 } derb;72 73 return 0; // Set a breakpoint here74}75