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

Scott Conger scott.conger at gmail.com
Tue Jul 12 13:53:31 PDT 2011

On Tue, Jul 12, 2011 at 1:08 PM, Chandler Carruth <chandlerc at google.com> wrote:
> On Tue, Jul 12, 2011 at 10:29 AM, Chris Lattner <clattner at apple.com> wrote:
>> On Jul 12, 2011, at 9:50 AM, Douglas Gregor wrote:
>> >> Besides, the chances of Clang actually helpfully diagnosing a problem
>> >> with the delta between how GCC does -Warray-bounds and how Clang does
>> >> it are slim - how often are these problems statically detectable? This
>> >> is C.
>> >
>> > We have empirical evidence that it *does* find bugs, otherwise we
>> > wouldn't still have the warning.
>> Do we have empirical evidence that it finds bugs in arrays with exactly 1
>> element?  I think we should just disable it in the case that the array has a
>> single element.  This really is a common pattern.
> I tend to agree, but maybe there is a good compromise. What about changing
> this warning to whitelist only one-element arrays which are inside of some
> record type? That would still catch local arrays, global arrays, etc.
> We could even then add a special (extension?) warning for one-element arrays
> inside of record types which are accessed passed the bounds only in modes
> where flexible array members are available, maybe even with a fixit note
> that converts the declaration.

Couldn't we be even more specific and require it to be the last member
of the struct/class?

More information about the cfe-dev mailing list