[cfe-dev] -Warray-bounds seems over-zealous on Clang
rjmccall at apple.com
Wed Jul 13 13:27:10 PDT 2011
On Jul 13, 2011, at 1:21 PM, John McCall wrote:
> On Jul 13, 2011, at 1:10 PM, Nicola Gigante wrote:
>> Il giorno 13/lug/2011, alle ore 17.49, Ted Kremenek ha scritto:
>>> On Jul 13, 2011, at 8:05 AM, David Blaikie wrote:
>>>> So, options that seem to be being discussed include:
>>>> 1) suppress this warning in all cases where the array is of length 1 and the last element in a struct
>>>> 1.1) refinement: only when the length is specified explicitly and not via macro expansion, etc. (as John suggested)
>>>> 1.2) refinement: under c99 recommend a fixup to use flexible arrays
>>>> 2) split the warning in two, the second being the cases suppressed by the above option (probably less interesting if 1.1 is implemented)
>>> (1) and (2) aren't mutually exclusive. (2) is still useful when the heuristics implied by 1.1 and 1.2 aren't good enough.
>> I've tried to write such a patch, as it seemed simple, but I'm stuck because I don't know enough
>> about internal clang's APIs yet.
>> Until now, I've come up with the simple patch attached, that disables the warning if
>> the array is declared inside a record type and the size is one.
>> - From the NamedDecl* object representing the array declaration, how do I know if it's declared last in the struct?
> It should be a FieldDecl, and its parent should be a RecordDecl. I don't think there's a cleaner solution than just iterating through the fields of the record and complaining if it's not the last one.
Oh, of course there's getNextDeclInContext(); you could just walk those (until you get a null pointer back) and make sure there aren't any FieldDecls.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev