This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: c-decl.c overhaul (1/3) Refactor duplicate_decls
- From: Richard Sandiford <rsandifo at redhat dot com>
- To: "Zack Weinberg" <zack at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 12 Jan 2004 17:44:17 +0000
- Subject: Re: c-decl.c overhaul (1/3) Refactor duplicate_decls
- References: <87u133wadv.fsf@egil.codesourcery.com>
"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