https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82609
Bug ID: 82609
Summary: missing -Warrray-bounds on an argument in parentheses
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
While testing my C/C++ patch for pr82588 I noticed the following rather bizarre
bug where a -Warray-bound warning for an out-of-bounds index is suppressed by
enclosing the invalid array reference in parentheses.
$ cat a.c && gcc -O2 -S -Wall -Warray-bounds -Wextra -xc++ a.c
extern char a[2];
extern char b[2];
int f (void)
{
return a[-1]; // -Warray-bounds (good)
}
int g (void)
{
return (b[-1]); // missing -Warray-bounds in C++ only
}
a.c: In function ‘int f()’:
a.c:6:14: warning: array subscript is below array bounds [-Warray-bounds]
return a[-1]; // -Warray-bounds (good)
~~~~^