From 94b94c0bb1ca52f2b6912852cb40240efe72e82b Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 17 Jun 2020 21:23:35 +0100 Subject: [PATCH] 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. --- .../uninitialized_default_n/sizes.cc | 29 ++++--------------- .../uninitialized_value_construct_n/sizes.cc | 29 ++++--------------- 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc index 1bb4c6a9fb1..6842c76df07 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc @@ -18,25 +18,14 @@ // { dg-do run { target c++11 } } #include -#include #include -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(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(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 diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc index e822b198928..7ad55e01157 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc @@ -19,25 +19,14 @@ // { dg-do run { target c++17 } } #include -#include #include -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(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(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 -- 2.30.2