This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Improve -Wc++-compat to warn about types defined inside structs

On Wed, 6 May 2009, Ian Lance Taylor wrote:

> In C it is valid to write
> struct s1 { struct s2 { int i; } f; };
> struct s2 v;
> This is invalid in C++, because struct s2 is defined inside struct s1.
> The only way to refer to struct s2 is to say s1::s2.
> The first patch in this message improves the C frontend to warn about
> this type of case.  The only types which can be defined inside a struct
> (or union) in C are struct, union, and enum types.  For those types, I
> use TYPE_LANG_FLAG_2, now known as C_TYPE_DEFINED_IN_STRUCT, to record
> whether the type was defined inside a struct.

As I read the patch, it will diagnose both those cases where C++ permits 
the definition inside a struct, and cases where the type is defined inside 
a cast or sizeof in an expression inside the struct definition, which are 
not permitted by C++ at all, but not other cases of types defined in casts 
and sizeof.  That is OK, but it would make sense to open a PR to record 
that type definitions in casts and sizeof shouldn't only be caught when 
inside struct definitions.  (I don't expect much code actually to use type 
definitions inside casts and sizeof.)

The patch should use something other than a TREE_LIST for the struct_types 
list; we'd like eventually to get rid of TREE_LIST, so introducing new 
uses of it is a bad idea.

Joseph S. Myers

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]