[PATCH] PR c++/33255 - Support -Wunused-local-typedefs warning

Jason Merrill jason@redhat.com
Sun Aug 7 07:46:00 GMT 2011


On 08/06/2011 06:57 AM, Dodji Seketeli wrote:
> @@ -4340,6 +4340,8 @@ c_sizeof_or_alignof_type (location_t loc,
>    value = fold_convert_loc (loc, size_type_node, value);
>    gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)));
>
> +  maybe_record_local_typedef_use (type);

Why is this still needed?

> +/* Return TRUE if DECL is declared in the current function.  */
> +
> +bool
> +local_decl_p (tree decl)

I don't think we need to work so hard to compare contexts to 
current_function_decl; just checking that the decl is in some function 
should be enough, i.e. decl_function_context is non-null.

> +  static int unused_local_typedefs_warn_count;

This could use a comment.

> +/* If T is a typedef variant type or a TYPE_DECL declared locally,
> +   mark it as used.  */
> +
> +void
> +maybe_record_local_typedef_use (tree t)

Does this still need to handle types?  And the meaning of TREE_USED 
shouldn't change depending on a warning flag or whether a decl is local 
or not; let's just mark all TYPE_DECLs as used.

Seems like we don't need local_decl_p at all; at the definition point, 
if we're in a function, a new declaration must be local enough for our 
purposes.

> +void
> +cp_maybe_record_local_typedef_use (tree t)
> +{
> +  /*  If the current function is being instantiated, bail out.  */

As above, I think we shouldn't put so many conditions on setting TREE_USED.

> @@ -19572,6 +19572,9 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
>    if (DECL_P (decl))
>      check_accessibility_of_qualified_id (decl, object_type, parser->scope);
>
> +  cp_maybe_record_local_typedef_use (decl);
> +  cp_maybe_record_local_typedef_use (parser->scope);

Why do we need to handle parser->scope?  Wasn't it previously looked up?



More information about the Gcc-patches mailing list