Re: How to diagnose a false positive warning
Georg-Johann Lay via Gcc-help <[email protected]> Mon, 18 May 2026 14:49:00 +0200
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <[email protected]> |
Am 13.05.26 um 05:43 schrieb Michael Welsh Duggan via Gcc-help: > g++ 16 ends up triggering a new false positive warning in some of my > code that didn't trigger in g++ 15. An example of this warning: > > In file included from /home/md5i/src/ipfix/master/tests/build.hpp:6, > from /home/md5i/src/ipfix/master/tests/read.cpp:7: > In function ‘void ipfix::convert::to_chunk_unsafe(auto:65&&, T) [with T = unsigned int; auto:65 = std::span<unsigned char>]’, > inlined from ‘build::message& build::message::set_domain(build::u32)’ at /home/md5i/src/ipfix/master/tests/build.hpp:202:29, > inlined from ‘virtual void ReadTest_EmptyMessages_Test::TestBody()’ at /home/md5i/src/ipfix/master/tests/read.cpp:262:19: > /home/md5i/src/ipfix/master/src/../include/detail/conversions.hpp:244:14: error: writing 4 bytes into a region of size 0 [-Werror=stringop-overflow=] > 244 | std::memcpy(data(chunk), start, size(chunk)); > | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In member function ‘virtual void ReadTest_EmptyMessages_Test::TestBody()’: > cc1plus: note: destination object is likely at address zero > > I'm fairly certain that this is a false positive, but the code is too > complex to reproduce here. I started to work on a minimal reproducer, > but, again, the code is quite layered and complex. I know I can ignore > the warning using diagnostic pragmas, but I prefer not to do that unless > completely necessary. Can anyone recommend a way to debug why this > warning is triggered? As far is I know, -Wstringop-overflow is basically broken, see for example https://gcc.gnu.org/PR88443 You can try to disable the warning with option pragmas, like #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstringop-overflow" #pragma GCC diagnostic pop etc. There are dozens / hundreds of test cases that expose false positives, dunno if adding yet another one would help much. Johann