This is the mail archive of the gcc-patches@gcc.gnu.org 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: c-decl.c overhaul (1/3) Refactor duplicate_decls


"Zack Weinberg" <zack@codesourcery.com> writes:
> +/* Another subroutine of diagnose_mismatched_decls.  OLDDECL is an
> +   old-style function definition, NEWDECL is a prototype declaration.
> +   Diagnose inconsistencies in the argument list.  Returns TRUE if
> +   the prototype is compatible, FALSE if not.  */
> +static bool
> +validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
> +{
> +  tree type, parm;
> +  int nargs;
> +  /* Prototype decl follows defn w/o prototype.  */
> +
> +  for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype),
> +	 type = TYPE_ARG_TYPES (newtype),
> +	 nargs = 1;
> +       ;
> +       parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++)
> +    {
> +      if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
> +	  && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
> +	{
> +	  /* End of list.  */
> +	  warning ("%Jprototype for '%D' follows non-prototype definition",
> +		   newdecl, newdecl);
> +	  return true;
> +	}
>  
> -  /* New decl is completely inconsistent with the old one =>
> -     tell caller to replace the old one.
> -     This is always an error except in the case of shadowing a builtin.  */
> +      if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
> +	  || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
> +	{
> +	  error ("%Jprototype for '%D' with different number of arguments "
> +		 "follows non-prototype definition", newdecl, newdecl);
> +	  return false;
> +	}
> +      /* Type for passing arg must be consistent
> +	 with that declared for the arg.  */
> +      if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type),
> +		       COMPARE_STRICT))
> +	{
> +	  error ("%Jprototype for '%D' with incompatible argument %d "
> +		 "follows non-prototype definition", newdecl, newdecl, nargs);
> +	  return false;
> +	}
> +    }
> +}

Missing "return true" at the end?

Richard


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