https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69359
Bug ID: 69359
Summary: Warn about constant comparisons between pointers and
arrays
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: fw at gcc dot gnu.org
Target Milestone: ---
This code fragment should result in a warning because p < a can never be true.
int *f (int *);
int g (void)
{
int a[3];
int *p = f (a);
return p < a;
}
This variant is even more clear:
int f (void);
int g (void)
{
int a[3];
int *p = a + f ();
return p < a;
}
Even for the following test case, it makes sense to warn because p <= a is
equivalent to p == a:
int f (void);
int g (void)
{
int a[3];
int *p = a + f ();
return p <= a;
}
(Observed with GCC 5.3 and trunk from a week ago.)
I set the component to tree-optimization; a purely type-based implementation in
the C/C++ front ends could make sense as well (although it would miss cases
where the array variable has already decayed to a pointer).