-Wstringop-overflow warning in std::string
Jonathan Wakely
jwakely@redhat.com
Fri Feb 28 13:20:00 GMT 2020
On 27/02/20 14:43 -0700, Martin Sebor wrote:
>>Should I just add -Wno-stringop-overflow to the testcase, or would it
>>be worth doing something like this to inform the compiler?
>
>I'm not sure. Since the ctor is undefined when passed a size in
>excess of the argument size the warning might be useful even if
>the library handles it. But then again, since the library handles
>it (at least in a subset of cases) it's not necessarily undefined.
Well, the library refuses to create a string of that size, but even
calling that constructor with those arguments is still undefined
because it violates the precondition that [str,str+n) is a valid
range.
So I think getting a warning from the compiler telling you that you're
doing something very wrong is useful. Just not in the context of this
test, because we know we're doing something dumb, that's part of the
test.
>For what it's worth, when I wrote the library we grappled with
>this question and ended up deciding that providing well-defined
>semantics for undefined behavior wasn't as helpful as it seemed
>at first unless we could do it reliably.
Yes, I think I'll just disable the warning in the testcase. Thanks for
your input.
The attached patch has been committed to master.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20200228/01c02f1d/attachment.bin>
More information about the Libstdc++
mailing list