Bug 82609 - missing -Warrray-bounds on an argument in parentheses
Summary: missing -Warrray-bounds on an argument in parentheses
Status: RESOLVED DUPLICATE of bug 74762
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Warray-bounds 83869
  Show dependency treegraph
 
Reported: 2017-10-18 18:08 UTC by Martin Sebor
Modified: 2018-01-15 21:31 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2017-10-18 18:08:41 UTC
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)
          ~~~~^
Comment 1 Manuel López-Ibáñez 2017-10-18 20:27:46 UTC
Almost surely this is PR74762. Or perhaps PR25733
Comment 2 Martin Sebor 2018-01-15 21:31:52 UTC
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 ***