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/C++ PATCH] Implement -Wsizeof-array-argument (PR c/6940)


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


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