<div>Adding cfe-dev. Removing llvm-dev.</div><div><br><div class="gmail_quote"><div>On Tue, Apr 18, 2017 at 7:55 AM Manuel Rigger via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi,<div><br></div><div>the C11 standard provides the following example for variable-length arrays and pointer arithmetics (see §6.5.6:10):</div><div><br></div><div><div>int main() {</div><div> int n = 4, m = 3;</div><div> int a[n][m];</div><div> int(*p)[m] = a;</div><div> assert(p == &a[0]);</div><div> p += 1;</div><div> assert(p == &a[1]);</div><div> (*p)[2] = 99;</div><div> assert(a[1][2] == 99);</div><div> n = p - a;</div><div> assert(n == 1);</div><div>}</div></div><div><br></div><div>When compiling the program with Clang 3.9, I get the following warning: </div><div><br></div><div>warning: subtraction of pointers to type 'int [m]' of zero size has undefined behavior [-Wpointer-arith]</div><div><br></div><div>This is confusing (and probably a bug), since m is not zero and both pointers refer to the same object. If I define a as int a[n][3] the warning no longer appears.</div><div><br></div><div>- Manuel</div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature">~Craig</div>