This is invalid C++: struct s1 { int i; } *p; int i = ((struct s2 { int j; } *)p)->j;
foo.cc:2: error: types may not be defined in casts By analogy, this should be invalid C++: int i = (struct s3 { int j; }) { 1 }.j; Currently g++ accepts it. Compound literals are an extension to C++, so there are no documented rules about them. However, it seems to be that when it comes to defining new types, they should be consistent with casts. -- Summary: g++ should not permit types to be defined in compound literals Product: gcc Version: 4.5.0 Status: UNCONFIRMED Keywords: accepts-invalid Severity: minor Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ian at airs dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076