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.

commit 86e2dc22c91a722d2624c0010d81f1ce4b911bbd
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Feb 27 17:22:50 2020 +0000

    libstdc++: Fix failing test in debug mode
    
    This fixes a failure due to a (correct) warning seen when testing with
    -D_GLIBCXX_USE_CXX11_ABI=0 -D_GLIBCXX_ASSERTIONS:
    
    include/bits/char_traits.h:365: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)'
    specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
    
    FAIL: 21_strings/basic_string/cons/char/1.cc (test for excess errors)
    
            * testsuite/21_strings/basic_string/cons/char/1.cc: Disable
            -Wstringop-overflow warnings.

diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/1.cc
index 66054588273..1c3e43f2fd4 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/1.cc
@@ -19,6 +19,8 @@
 
 // 21.3.1 basic_string constructors.
 
+// { dg-options "-Wno-stringop-overflow" }
+
 #include <new>
 #include <stdexcept>
 #include <testsuite_hooks.h>

Reply via email to