This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C PATCH] Disallow subtracting pointers to empty structs (PR c/58346)
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>, Jason Merrill <jason at redhat dot com>
- Date: Tue, 14 Jan 2014 21:42:37 +0000
- Subject: Re: [C PATCH] Disallow subtracting pointers to empty structs (PR c/58346)
- Authentication-results: sourceware.org; auth=none
- References: <20140113163226 dot GD4458 at redhat dot com> <20140113164859 dot GE4458 at redhat dot com> <20140113204839 dot GF4458 at redhat dot com>
On Mon, 13 Jan 2014, Marek Polacek wrote:
> +/* Return true if T is a pointer to a zero-sized struct/union. */
> +
> +bool
> +pointer_to_zero_sized_aggr_p (tree t)
> +{
> + t = strip_pointer_operator (t);
> + if (RECORD_OR_UNION_TYPE_P (t)
> + && TYPE_SIZE (t)
> + && integer_zerop (TYPE_SIZE (t)))
> + return true;
> + return false;
Given that GNU C also allows arrays of constant size 0, shouldn't the
errors also apply in that case? (I don't know whether the original bug
can appear for such arrays, but I'd think the errors should apply to
anything with constant size 0 - not of course for VLAs where it just so
happens that the compiler can tell at compile time that the size is always
0.)
--
Joseph S. Myers
joseph@codesourcery.com