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) ~~~~^
Almost surely this is PR74762. Or perhaps PR25733
The problem is caused by the finish_parenthesized_expr() function in cp/semantics.c setting the TREE_NO_WARNING bit, as mentioned in bug 74762, comment 1 (see the snippet from that file copied below). So this is indeed a dupe of that bug. /* Finish a parenthesized expression EXPR. */ cp_expr finish_parenthesized_expr (cp_expr expr) { if (EXPR_P (expr)) /* This inhibits warnings in c_common_truthvalue_conversion. */ TREE_NO_WARNING (expr) = 1; *** This bug has been marked as a duplicate of bug 74762 ***