This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/44300] Spurious array subscript warning
- From: "jmattson at vmware dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 May 2010 20:31:24 -0000
- Subject: [Bug c/44300] Spurious array subscript warning
- References: <bug-44300-19243@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from jmattson at vmware dot com 2010-05-27 20:31 -------
Admittedly, foo() makes some assumptions about alignment as originally written.
A more pedantic version is:
static inline void
foo(int *p)
{
if (p >= a + 1 && p < a + 10) {
p[-1] = 0;
}
}
gcc still generates a warning with this version.
Even if a[] and b[] overlap, the guard clause ensures that the expression
'p[-1]' is within the bounds of array a[].
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44300