>> void foo(int n) {
>>   char x[5];
>>   if (n > 0) bar(x + 6 - n);
>> }
>
> Strictly speaking, that isn't a false positive... I can't think of how
> we would actually produce anything other than the expected result,

[I'm not sure how closely you were considering your knowledge of the
implementation of clang (which is no doubt greater than my own)
compared to things a C++ compiler could possibly do, even if clang
doesn't do them today.]

Actually it's not so hard to imagine a case just like this where this
UB could result in some interesting results. It wouldn't be hard for
the compiler to prove that x + 6 is out of range, therefor the
condition (n > 0) must always be false, so it could just remove the
code entirely. Chris gave some similar examples in his blog series on
UB.

- David

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to