[cfe-dev] -Warray-bounds seems over-zealous on Clang

Peter Geoghegan peter at 2ndquadrant.com
Tue Jul 12 16:17:43 PDT 2011

On 12 July 2011 23:52, Reid Kleckner <reid.kleckner at gmail.com> wrote:
> My inclination and I believe the inclination of others is that, if it
> catches real bugs, which Nico has shown it has, then it's worth having
> the warning.

It's going to cause spurious warnings for a large number of real-world
applications. Do you think that that will endear developers of those
applications to Clang? The fact that it may catch bugs in some
extremely unlikely scenario (recall that I only want to avoid the
warning for this very specific case) should not outweigh this. Isn't
that obvious?

> Another compromise would be to have a flag about bounds
> checks warnings for size 1 arrays at the end of structs (phew).  =P

As I said, I would think it reasonable if the warning was disabled for
this exact pattern only, so that for example it would not occur if the
array had more than 1 element, or wasn't the last piece of data in the

> If you can't use C99, are flexible arrays available as an extension in
> clang, either in gnu89 or via some flag?  If so, you could use ifdefs
> like this:
> #ifdef __GNUC__
> /* or some other condition, __has_feature or what have you */
> #else
> #define FLEXIBLE_ARRAY 1
> #endif
> struct Buffer {
>  int len;
>  char bytes[FLEXIBLE_ARRAY];
> };
> It's even self-documenting.

It's gross. Our community is obsessed with code hygiene, and that will
never fly just to get Clang to stop complaining while every single
other compiler, of which there are quite a few (PostgreSQL is supposed
to be highly portable), will not complain.

Peter Geoghegan       http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services

More information about the cfe-dev mailing list