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

David Blaikie dblaikie at gmail.com
Tue Jul 12 16:28:45 PDT 2011


>
> > #ifdef __GNUC__
> > /* or some other condition, __has_feature or what have you */
> > #define FLEXIBLE_ARRAY
> > #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.
>

What exactly do you mean by code hygiene in this regard? Why would the above
be unhygienic?

I think someone mentioned the idea of adding a separate warning for this
narrower case and, in the case of compiling for c99, suggesting a fixup of
using a flexible array. In the case of c89 at least it'd be a separate
warning that, if the pattern is used extensively in the codebase, could be
disabled separately from the more general warning (which would be adjusted
to ignore these cases).

This would allow for the bug that was mentioned to have been found, while
allowing you to disable this warning if you don't think the chance of such
bugs coming up is worth the code hygiene cost of the above construct or the
move to c99 would be worthwhile in your case.

- David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110712/00aae29a/attachment.html>


More information about the cfe-dev mailing list