libstdc++: Fix tests for uninitialized_value_construct_n

In my recent r11-1460 commit the tests had been "improved" before
commit, and no longer exercised the code paths changed by the patch.

This restores what I originally tested, so that the tests fail before
the r11-1460 change and pass after it.

	* testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc:
	Replace Value type with int so trivial code path is used.
	* testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc:
	Likewise.
This commit is contained in:
Jonathan Wakely 2020-06-17 21:23:35 +01:00
parent c9dce3b15e
commit 94b94c0bb1
2 changed files with 12 additions and 46 deletions

View file

@ -18,25 +18,14 @@
// { dg-do run { target c++11 } }
#include <memory>
#include <algorithm>
#include <testsuite_hooks.h>
struct Value
{
int value = 0x1234;
};
void
test01()
{
alignas(Value) unsigned char buf[3 * sizeof(Value) + 1];
std::fill(std::begin(buf), std::end(buf), 0xff);
const auto p = reinterpret_cast<Value*>(buf);
std::__uninitialized_default_n(p, 2.0001);
VERIFY( p[0].value == 0x1234 );
VERIFY( p[1].value == 0x1234 );
VERIFY( p[2].value == 0x1234 );
VERIFY( *std::prev(std::end(buf)) == 0xff );
int i[3];
auto j = std::__uninitialized_default_n(i, 2.0001);
VERIFY( j == (i + 3) );
}
void
@ -52,16 +41,10 @@ test02()
int operator>(void*) { return value != 0; }
};
alignas(Value) unsigned char buf[4 * sizeof(Value) + 1];
std::fill(std::begin(buf), std::end(buf), 0xff);
const auto p = reinterpret_cast<Value*>(buf);
int i[3];
Size n = {4};
std::__uninitialized_default_n(p, n);
VERIFY( p[0].value == 0x1234 );
VERIFY( p[1].value == 0x1234 );
VERIFY( p[2].value == 0x1234 );
VERIFY( p[3].value == 0x1234 );
VERIFY( *std::prev(std::end(buf)) == 0xff );
auto j = std::__uninitialized_default_n(i, n);
VERIFY( j == (i + 4) );
}
int

View file

@ -19,25 +19,14 @@
// { dg-do run { target c++17 } }
#include <memory>
#include <algorithm>
#include <testsuite_hooks.h>
struct Value
{
int value = 0x1234;
};
void
test01()
{
alignas(Value) unsigned char buf[3 * sizeof(Value) + 1];
std::fill(std::begin(buf), std::end(buf), 0xff);
const auto p = reinterpret_cast<Value*>(buf);
std::uninitialized_value_construct_n(p, 2.0001);
VERIFY( p[0].value == 0x1234 );
VERIFY( p[1].value == 0x1234 );
VERIFY( p[2].value == 0x1234 );
VERIFY( *std::prev(std::end(buf)) == 0xff );
int i[3];
auto j = std::uninitialized_value_construct_n(i, 2.0001);
VERIFY( j == (i + 3) );
}
void
@ -53,16 +42,10 @@ test02()
int operator>(void*) { return value != 0; }
};
alignas(Value) unsigned char buf[4 * sizeof(Value) + 1];
std::fill(std::begin(buf), std::end(buf), 0xff);
const auto p = reinterpret_cast<Value*>(buf);
int i[3];
Size n = {4};
std::uninitialized_value_construct_n(p, n);
VERIFY( p[0].value == 0x1234 );
VERIFY( p[1].value == 0x1234 );
VERIFY( p[2].value == 0x1234 );
VERIFY( p[3].value == 0x1234 );
VERIFY( *std::prev(std::end(buf)) == 0xff );
auto j = std::__uninitialized_default_n(i, n);
VERIFY( j == (i + 4) );
}
int