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: [PATCH 1/3] add -Wstruct-not-pod, -Wclass-is-pod, -Wmismatched-tags (PR 61339)

On 7/8/19 3:58 PM, Martin Sebor wrote:
> The attached patch implements three new warnings:
>  *  -Wstruct-not-pod triggers for struct definitions that are not
>     POD structs,
>  *  -Wclass-is-pod triggers for class definitions that satisfy
>     the requirements on POD structs, and
>  *  -Wmismatched-tags that triggers for class and struct declarations
>     with class-key that doesn't match either their definition or
>     the first declaration (if no definition is provided).
> The implementation of -Wclass-is-pod and -Wstruct-not-pod is fairly
> straightforward but the -Wmismatched-tags solution is slightly unusual.
> It collects struct and class declarations first and diagnoses mismatches
> only after the whole tramslation unit has been processed.  This is so
> that the definition of a class can guide which declarations to diagnose
> no matter which come first.
> Martin
> gcc-61339-impl.diff
> gcc/c-family/ChangeLog:
> 	* c.opt (-Wstruct-not-pod, -Wclass-is-pod): New options.
> 	(-Wmismatched-tags): Same.
> gcc/cp/ChangeLog:
> 	* parser.c (maybe_warn_struct_vs_class): New function.
> 	(cp_parser_check_class_key): Add argument.
> 	(cp_parser_type_specifier): Call maybe_warn_struct_vs_class.
> 	(cp_parser_elaborated_type_specifier): Call maybe_warn_struct_vs_class
> 	before setting CLASSTYPE_DECLARED_CLASS.  Avoid setting it for classes
> 	that are in the process of being defined.
> 	(cp_parser_class_head): Call maybe_warn_struct_vs_class.
> 	(class_or_template_pod_p): New static function.
> 	(maybe_warn_struct_vs_class) Same.
> 	(class rec_decl_loc_t): New.
> 	(cp_parser_check_class_key): Record a struct declaration.
> 	(diag_mismatched_tags): Hanlde -Wmismatched-tags.
> 	(c_parse_file): Call diag_mismatched_tags.
> gcc/ChangeLog:
> 	* doc/invoke.texi (-Wstruct-not-pod, -Wclass-is-pod): Document new
> 	options.
> 	(-Wmismatched-tags): Same.
So I'm going to defer to Jason here given this is a front-end patch.
Your call whether or not to push on it prior to getting any resolution
on changing GCC's conventions.


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