public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-1461] libstdc++: Fix tests for uninitialized_value_construct_n Date: Wed, 17 Jun 2020 20:28:19 +0000 (GMT) [thread overview] Message-ID: <20200617202819.25C723985C3D@sourceware.org> (raw) https://gcc.gnu.org/g:94b94c0bb1ca52f2b6912852cb40240efe72e82b commit r11-1461-g94b94c0bb1ca52f2b6912852cb40240efe72e82b Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Jun 17 21:23:35 2020 +0100 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. Diff: --- .../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 <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 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 <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
reply other threads:[~2020-06-17 20:28 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200617202819.25C723985C3D@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).