libstdc++: Suppress -Wstringop-overread warning in test

When compiled with -m32 -O2 -D_GLIBCXX_USE_CXX11_ABI=0 we get a warning
for 21_strings/basic_string/cons/char/1.cc:

bits/char_traits.h:409:56: warning: ‘void* __builtin_memcpy(void*, const void*, unsigned int)’ reading 1073741821 bytes from a region of size 19 [-Wstringop-overread]

The warning is legitimate, even if that line cannot be reached because
we throw std::length_error before getting there. Since the invalid
length is deliberate (and mentioned in a comment) just suppress the
warning, so that the test can verify we get the exception.

Also remove an unused typedef that produces another warning.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/cons/char/1.cc: Use
	diagnostic pragma to suppress -Wstringop-overread error.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
This commit is contained in:
Jonathan Wakely 2021-06-18 11:08:19 +01:00
parent 76e990fd21
commit 92edc4a768

View File

@ -36,7 +36,6 @@ using namespace std;
void test01(void) void test01(void)
{ {
typedef string::size_type csize_type; typedef string::size_type csize_type;
typedef string::iterator citerator;
csize_type npos = string::npos; csize_type npos = string::npos;
csize_type csz01; csize_type csz01;
@ -68,6 +67,8 @@ void test01(void)
// basic_string(const char* s, size_type n, alloc) // basic_string(const char* s, size_type n, alloc)
csz01 = str01.max_size(); csz01 = str01.max_size();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overread"
// NB: As strlen(str_lit01) != csz01, this test is undefined. It // NB: As strlen(str_lit01) != csz01, this test is undefined. It
// should not crash, but what gets constructed is a bit arbitrary. // should not crash, but what gets constructed is a bit arbitrary.
try { try {
@ -94,6 +95,7 @@ void test01(void)
catch(...) { catch(...) {
VERIFY( false ); VERIFY( false );
} }
#pragma GCC diagnostic pop
// Build a maxsize - 1 lengthed string consisting of all A's // Build a maxsize - 1 lengthed string consisting of all A's
try { try {