-Warray-bounds false positive?

Hi all,

I'm not enough of a language lawyer to be 100% sure, but:

Yes. File a bug? :slight_smile:

No, the warning is legit. sizeof() returns the size in bytes, not elements. This is an array of doubles.

But it's been casted to char *. This is equivalent to this code:

double foo[4096];
char *bar = (char *)foo;
bar[sizeof(foo)-1] = '\0';

I mean, it's probably a bad idea, but it's not an out-of-bounds error.

Ah, you're right. We should adjust the array size in the warning based on the pointer type being accessed.

Jordy et al,

The check should be accounting for the array being cast to char*… not sure why it isn’t (and in the middle of trying to refactor ActOnFunctionDeclarator). When the bug is filed you can assign it it me, as I’ve already done a lot of work on improving -Warray-bounds and would like to know/dig into why the false positive is triggering.


Thanks for making me not the only one to be momentarily confused! :slight_smile:

I filed: