https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122197
Aykhan Hagverdili <hagverdilia at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hagverdilia at gmail dot com
--- Comment #30 from Aykhan Hagverdili <hagverdilia at gmail dot com> ---
Here is a small standalone reproducer for the `-Warray-bounds` side of this
issue on current trunk:
```
$ git -C ../gcc-src rev-parse HEAD
e8ec1a6b68e6d453dba899b4680a95b3c7e171df
$ ../gcc-install/bin/g++ -v
Using built-in specs.
COLLECT_GCC=../gcc-install/bin/g++
COLLECT_LTO_WRAPPER=/home/ayxan/src/gcc-install/bin/../libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-src/configure
--prefix=/home/ayxan/src/gcc-build/../gcc-install --enable-languages=c,c++
--disable-multilib --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20261126 (experimental) (GCC)
$ cat main.cpp
struct Interface {
virtual ~Interface() = default;
};
struct Adaptor : Interface {
Interface* object = new Interface;
int* cache{};
~Adaptor() { delete object; delete cache; }
};
void external();
void reproduce()
{
Adaptor adaptor;
external();
}
$ ../gcc-install/bin/g++ -c main.cpp -O3 -Warray-bounds
In destructor ‘virtual Adaptor::~Adaptor()’,
inlined from ‘virtual Adaptor::~Adaptor()’ at main.cpp:8:47,
inlined from ‘virtual Adaptor::~Adaptor()’ at main.cpp:8:25,
inlined from ‘void reproduce()’ at main.cpp:17:1:
main.cpp:8:25: warning: array subscript ‘Adaptor[0]’ is partly outside array
bounds of ‘unsigned char [8]’ [-Warray-bounds=]
8 | ~Adaptor() { delete object; delete cache; }
| ^~~~~~
In constructor ‘constexpr Adaptor::Adaptor()’,
inlined from ‘void reproduce()’ at main.cpp:15:13:
main.cpp:5:8: note: object of size 8 allocated by ‘operator new’
5 | struct Adaptor : Interface {
| ^~~~~~~
In destructor ‘virtual Adaptor::~Adaptor()’,
inlined from ‘virtual Adaptor::~Adaptor()’ at main.cpp:8:47,
inlined from ‘virtual Adaptor::~Adaptor()’ at main.cpp:8:25,
inlined from ‘void reproduce()’ at main.cpp:17:1:
main.cpp:8:40: warning: array subscript ‘Adaptor[0]’ is partly outside array
bounds of ‘unsigned char [8]’ [-Warray-bounds=]
8 | ~Adaptor() { delete object; delete cache; }
| ^~~~~
In constructor ‘constexpr Adaptor::Adaptor()’,
inlined from ‘void reproduce()’ at main.cpp:15:13:
main.cpp:5:8: note: object of size 8 allocated by ‘operator new’
5 | struct Adaptor : Interface {
| ^~~~~~~
In destructor ‘virtual Adaptor::~Adaptor()’,
inlined from ‘virtual Adaptor::~Adaptor()’ at main.cpp:8:47,
inlined from ‘virtual Adaptor::~Adaptor()’ at main.cpp:8:25,
inlined from ‘void reproduce()’ at main.cpp:17:1:
main.cpp:8:47: warning: array subscript ‘Adaptor[0]’ is partly outside array
bounds of ‘unsigned char [8]’ [-Warray-bounds=]
8 | ~Adaptor() { delete object; delete cache; }
| ^
In constructor ‘constexpr Adaptor::Adaptor()’,
inlined from ‘void reproduce()’ at main.cpp:15:13:
main.cpp:5:8: note: object of size 8 allocated by ‘operator new’
5 | struct Adaptor : Interface {
| ^~~~~~~
```
Seems to have been introduced in GCC 16, compiles cleanly with no warnings in
GCC 15.3
Compiler explorer:
GCC Trunk: https://godbolt.org/z/3bT3x9YYM
GCC 16.1: https://godbolt.org/z/6a95z9zW1
GCC 15.3: https://godbolt.org/z/9PrnEEKxv