Re: How to diagnose a false positive warning
Segher Boessenkool <[email protected]> Mon, 18 May 2026 10:40:16 -0500
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <agsy4KSrFkl7uJIK@gate> |
Hi! On Tue, May 12, 2026 at 11:43:33PM -0400, Michael Welsh Duggan via Gcc-help wrote: > 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? *All* warnings have false positives, that is why they are made warnings (and not errors). This is one of the reasons why -Werror is essentially always a stupid and irresponsible thing to do, btw. "region of size 0" sounds like either the compiler has a bug in determining the size, or the user code is actually wrong, or the compiler did not actually know the size and the warning uses the most pessimistic case (and the diagnostic message can use some improvement). Without showing us the code, no one can tell which it is. Segher