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

Nicola Gigante nicola.gigante at gmail.com
Fri Jul 15 09:39:23 PDT 2011

Il giorno 15/lug/2011, alle ore 14.24, Peter Geoghegan ha scritto:

> While I thank you for your efforts, I don't see why we have to
> explicitly use C89 to avoid the warning, since we're only avoiding the
> warning under circumstances exactly consistent with the use of the
> idiom.
> What's valid in C89 is valid in C99, with very few exceptions. Just
> because this is arguably bad style in C99 does not mean that we should
> see a warning - warnings are supposed to prevent downright errors that
> are still valid code. No one would seriously suggest that we should
> have warnings when C style casts are used in C++ on non-POD types,
> even though they're extremely hazardous there. Precedent matters.

Hm, I just tried to implement what seemed to be the general accepted solution
to your problem.
That said, if I understand your point, you want to develop a huge crossplatform
codebase written in C, but:
- You can't fully use C99 because some compilers won't support it (MSVC).
- So your code is C89, but you can force C89 compliance because you rely
  on some widely supported C99 feature (I suppose these are trivial things like
  mixing declarations and code or //-style comments, or the scope of the
  for() initializers, what else?)
- You want to support a lot of platforms and compilers, but you're reluctant 
  to tune your build system for specific compilers
- You don't want to deal with compilers differences with macro tricks because
  of "code hygiene"
- You want your code to compile warning-clean on all the compilers you support,
  but without disabling warnings from the command line.

Clang or not, I don't think these requirements are generally easy to fulfill,
you need to make a choice.

Anyway, this patch suppress the warning also in -std=gnu89 mode, which 
is the default for gcc, so you could simply pass -std=gnu89 to both compilers
and you'll have true drop-in compatibility.

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


P.S. this was just an exercise to me, so reviews for the patch are welcomed anyway
P.P.S. clang accepts flexibles arrays also with -std=c89 -pedantic. Is it compliant?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110715/f3e00465/attachment.html>

More information about the cfe-dev mailing list