public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104603] New: wrong detection of g++ -Warray-bounds about downcast
@ 2022-02-19  5:21 herumi at nifty dot com
  2022-02-19  5:46 ` [Bug c++/104603] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: herumi at nifty dot com @ 2022-02-19  5:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104603

            Bug ID: 104603
           Summary: wrong detection of g++ -Warray-bounds about downcast
           Product: gcc
           Version: 10.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: herumi at nifty dot com
  Target Milestone: ---

Created attachment 52477
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52477&action=edit
a minimal sample of the bug

g++-10.3.0 and g++-11.2 -O2 -Warray-bounds on Ubuntu 20.04.3 LTS show wrong
warnings to the attachment code.

g++ -O2 -Warray-bounds -DA t.cpp does not show the warnings.
g++-9 -O2 -Warray-bounds does not, too.

---
>cat t.cpp
struct Base {
  bool isX_;
  Base(bool isX = false) : isX_(isX) { }
  bool isX() const { return isX_; }
  bool operator==(const Base& rhs) const;
};

struct X : public Base {
  X(const Base& b) : Base(true), b_(b) { }
  bool operator==(const X& rhs) const { return b_ == rhs.b_; }
  Base b_;
};

inline bool Base::operator==(const Base& rhs) const
{
    return isX() && rhs.isX() && static_cast<const X&>(*this) ==
static_cast<const X&>(rhs);
}

Base base;

#ifndef A
void f()
{
  X(base) == X(base);
}
#endif

int main()
{
#ifdef A
  X(base) == X(base);
#endif
}
---

---
% g++-10 --version
g++-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
% g++-10 -O2 -Warray-bounds array-bounds-bug.cpp
array-bounds-bug.cpp: In function 'void f()':
array-bounds-bug.cpp:18:29: warning: array subscript 2 is outside array bounds
of 'X [1]' [-Warray-bounds]
   18 |   bool isX() const { return isX_; }
      |                             ^~~~
array-bounds-bug.cpp:38:9: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |         ^
array-bounds-bug.cpp:18:29: warning: array subscript 2 is outside array bounds
of 'X [1]' [-Warray-bounds]
   18 |   bool isX() const { return isX_; }
      |                             ^~~~
array-bounds-bug.cpp:38:20: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |                    ^
array-bounds-bug.cpp:18:29: warning: array subscript 3 is outside array bounds
of 'X [1]' [-Warray-bounds]
   18 |   bool isX() const { return isX_; }
      |                             ^~~~
array-bounds-bug.cpp:38:9: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |         ^
array-bounds-bug.cpp:18:29: warning: array subscript 3 is outside array bounds
of 'X [1]' [-Warray-bounds]
   18 |   bool isX() const { return isX_; }
      |                             ^~~~
array-bounds-bug.cpp:38:20: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |                    ^
array-bounds-bug.cpp:18:29: warning: array subscript 4 is outside array bounds
of 'X [1]' [-Warray-bounds]
   18 |   bool isX() const { return isX_; }
      |                             ^~~~
array-bounds-bug.cpp:38:9: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |         ^
array-bounds-bug.cpp:18:29: warning: array subscript 4 is outside array bounds
of 'X [1]' [-Warray-bounds]
   18 |   bool isX() const { return isX_; }
      |                             ^~~~
array-bounds-bug.cpp:38:20: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |                    ^
array-bounds-bug.cpp:18:29: warning: array subscript 5 is outside array bounds
of 'X [1]' [-Warray-bounds]
   18 |   bool isX() const { return isX_; }
      |                             ^~~~
array-bounds-bug.cpp:38:9: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |         ^
array-bounds-bug.cpp:18:29: warning: array subscript 5 is outside array bounds
of 'X [1]' [-Warray-bounds]
   18 |   bool isX() const { return isX_; }
      |                             ^~~~
array-bounds-bug.cpp:38:20: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |                    ^
array-bounds-bug.cpp:24:51: warning: array subscript 2 is outside array bounds
of 'X [1]' [-Warray-bounds]
   24 |   bool operator==(const X& rhs) const { return b_ == rhs.b_; }
      |                                                ~~~^~~~~~~~~
array-bounds-bug.cpp:38:9: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
      |         ^
array-bounds-bug.cpp:24:58: warning: array subscript 2 is outside array bounds
of 'X [1]' [-Warray-bounds]
   24 |   bool operator==(const X& rhs) const { return b_ == rhs.b_; }
      |                                                      ~~~~^~
array-bounds-bug.cpp:38:20: note: while referencing '<anonymous>'
   38 |   X(base) == X(base);
---

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-07-07 10:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-19  5:21 [Bug c++/104603] New: wrong detection of g++ -Warray-bounds about downcast herumi at nifty dot com
2022-02-19  5:46 ` [Bug c++/104603] " pinskia at gcc dot gnu.org
2022-02-19  5:51 ` [Bug tree-optimization/104603] [10/11/12 Regression] wrong detection of -Warray-bounds for interesting tail resusive case pinskia at gcc dot gnu.org
2022-02-19  6:15 ` herumi at nifty dot com
2022-02-19  6:22 ` pinskia at gcc dot gnu.org
2022-02-19  6:48 ` herumi at nifty dot com
2022-02-19  6:53 ` pinskia at gcc dot gnu.org
2022-02-19  7:40 ` herumi at nifty dot com
2022-03-01 20:51 ` msebor at gcc dot gnu.org
2022-03-09 13:03 ` rguenth at gcc dot gnu.org
2022-06-28 10:48 ` [Bug tree-optimization/104603] [10/11/12/13 " jakub at gcc dot gnu.org
2023-07-07 10:42 ` [Bug tree-optimization/104603] [11/12/13/14 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).