This is the mail archive of the
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
Then the name should be -Wsizeof-array-parm, not -argument.
@@ -9550,6 +9551,8 @@ grokdeclarator (const cp_declarator *declarator,
returned_attrs = chainon (returned_attrs,
+ if (decl_context == PARM)
+ array_parameter_p = true;
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
/* 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;