This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C/C++ PATCH] Implement -Wsizeof-array-argument (PR c/6940)
- From: Jason Merrill <jason at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jakub Jelinek <jakub at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Wed, 02 Jul 2014 19:27:07 -0700
- Subject: Re: [C/C++ PATCH] Implement -Wsizeof-array-argument (PR c/6940)
- Authentication-results: sourceware.org; auth=none
- References: <20140626222238 dot GF489 at redhat dot com>
On 06/26/2014 03:22 PM, Marek Polacek wrote:
The following is a revamped patch for -Wsizeof-array-argument.
Its purpose is to detect suspicious usage of the sizeof operator on an array
function parameter.
Then the name should be -Wsizeof-array-parm, not -argument.
@@ -9550,6 +9551,8 @@ grokdeclarator (const cp_declarator *declarator,
array. */
returned_attrs = chainon (returned_attrs,
declarator->std_attributes);
+ if (decl_context == PARM)
+ array_parameter_p = true;
break;
Setting this here means that you'll treat a parameter with
pointer-to-array type as an array parm. I think you want to set it
here, instead:
/* A parameter declared as an array of T is really a pointer to T.
One declared as a function is really a pointer to a function.
One declared as a member is really a pointer to member. */
if (TREE_CODE (type) == ARRAY_TYPE)
{
/* Transfer const-ness of array into that of type pointed to. */
type = build_pointer_type (TREE_TYPE (type));
type_quals = TYPE_UNQUALIFIED;
}
Jason