From e06cde870edc7ec21736145b6857565d4b2f0e85 Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Sat, 22 Feb 2020 22:40:26 +0200 Subject: [PATCH] Library-side tests for parenthesized aggregate init PR c++/92878 PR c++/92947 * testsuite/20_util/allocator_traits/members/92878_92947.cc: New. * testsuite/20_util/any/assign/92878_92947.cc: Likewise. * testsuite/20_util/any/cons/92878_92947.cc: Likewise. * testsuite/20_util/is_constructible/92878_92947.cc: Likewise. * testsuite/20_util/optional/assignment/92878_92947.cc: Likewise. * testsuite/20_util/optional/cons/92878_92947.cc: Likewise. * testsuite/20_util/pair/cons/92878_92947.cc: Likewise. * testsuite/20_util/shared_ptr/creation/92878_92947.cc: Likewise. * testsuite/20_util/specialized_algorithms/construct_at/92878_92947.cc: Likewise. * testsuite/20_util/unique_ptr/creation/92878_92947.cc: Likewise. * testsuite/20_util/uses_allocator/92878_92947.cc: Likewise. * testsuite/20_util/variant/92878_92947.cc: Likewise. * testsuite/23_containers/deque/modifiers/emplace/92878_92947.cc: Likewise. * testsuite/23_containers/forward_list/modifiers/92878_92947.cc: Likewise. * testsuite/23_containers/list/modifiers/emplace/92878_92947.cc: Likewise. * testsuite/23_containers/map/modifiers/emplace/92878_92947.cc: Likewise. * testsuite/23_containers/multimap/modifiers/emplace/92878_92947.cc: Likewise. * testsuite/23_containers/multiset/modifiers/emplace/92878_92947.cc: Likewise. * testsuite/23_containers/priority_queue/92878_92947.cc: Likewise. * testsuite/23_containers/queue/92878_92947.cc: Likewise. * testsuite/23_containers/set/modifiers/emplace/92878_92947.cc: Likewise. * testsuite/23_containers/stack/92878_92947.cc: Likewise. * testsuite/23_containers/unordered_map/modifiers/92878_92947.cc: Likewise. * testsuite/23_containers/unordered_multimap/modifiers/92878_92947.cc: Likewise. * testsuite/23_containers/unordered_multiset/modifiers/92878_92947.cc: Likewise. * testsuite/23_containers/unordered_set/modifiers/92878_92947.cc: Likewise. * testsuite/23_containers/vector/modifiers/emplace/92878_92947.cc: Likewise. --- libstdc++-v3/ChangeLog | 48 ++++++ .../allocator_traits/members/92878_92947.cc | 51 +++++++ .../20_util/any/assign/92878_92947.cc | 46 ++++++ .../testsuite/20_util/any/cons/92878_92947.cc | 46 ++++++ .../20_util/is_constructible/92878_92947.cc | 49 +++++++ .../optional/assignment/92878_92947.cc | 47 ++++++ .../20_util/optional/cons/92878_92947.cc | 46 ++++++ .../20_util/pair/cons/92878_92947.cc | 49 +++++++ .../shared_ptr/creation/92878_92947.cc | 46 ++++++ .../construct_at/92878_92947.cc | 50 +++++++ .../unique_ptr/creation/92878_92947.cc | 46 ++++++ .../20_util/uses_allocator/92878_92947.cc | 67 +++++++++ .../testsuite/20_util/variant/92878_92947.cc | 91 ++++++++++++ .../deque/modifiers/emplace/92878_92947.cc | 62 ++++++++ .../forward_list/modifiers/92878_92947.cc | 62 ++++++++ .../list/modifiers/emplace/92878_92947.cc | 78 ++++++++++ .../map/modifiers/emplace/92878_92947.cc | 137 ++++++++++++++++++ .../multimap/modifiers/emplace/92878_92947.cc | 71 +++++++++ .../multiset/modifiers/emplace/92878_92947.cc | 70 +++++++++ .../priority_queue/92878_92947.cc | 52 +++++++ .../23_containers/queue/92878_92947.cc | 47 ++++++ .../set/modifiers/emplace/92878_92947.cc | 70 +++++++++ .../23_containers/stack/92878_92947.cc | 47 ++++++ .../unordered_map/modifiers/92878_92947.cc | 137 ++++++++++++++++++ .../modifiers/92878_92947.cc | 71 +++++++++ .../modifiers/92878_92947.cc | 78 ++++++++++ .../unordered_set/modifiers/92878_92947.cc | 78 ++++++++++ .../vector/modifiers/emplace/92878_92947.cc | 61 ++++++++ 28 files changed, 1803 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/allocator_traits/members/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/any/assign/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/any/cons/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/is_constructible/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/optional/assignment/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/optional/cons/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/pair/cons/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/shared_ptr/creation/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/unique_ptr/creation/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/uses_allocator/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/20_util/variant/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/forward_list/modifiers/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/map/modifiers/emplace/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/multimap/modifiers/emplace/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/multiset/modifiers/emplace/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/priority_queue/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/queue/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/set/modifiers/emplace/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/stack/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multimap/modifiers/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/92878_92947.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/92878_92947.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 912bab28691..beaf61b9d2b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,51 @@ +2020-03-31 Ville Voutilainen + + Library-side tests for parenthesized aggregate init + + PR c++/92878 + PR c++/92947 + + * testsuite/20_util/allocator_traits/members/92878_92947.cc: New. + * testsuite/20_util/any/assign/92878_92947.cc: Likewise. + * testsuite/20_util/any/cons/92878_92947.cc: Likewise. + * testsuite/20_util/is_constructible/92878_92947.cc: Likewise. + * testsuite/20_util/optional/assignment/92878_92947.cc: Likewise. + * testsuite/20_util/optional/cons/92878_92947.cc: Likewise. + * testsuite/20_util/pair/cons/92878_92947.cc: Likewise. + * testsuite/20_util/shared_ptr/creation/92878_92947.cc: Likewise. + * testsuite/20_util/specialized_algorithms/construct_at/92878_92947.cc: + Likewise. + * testsuite/20_util/unique_ptr/creation/92878_92947.cc: Likewise. + * testsuite/20_util/uses_allocator/92878_92947.cc: Likewise. + * testsuite/20_util/variant/92878_92947.cc: Likewise. + * testsuite/23_containers/deque/modifiers/emplace/92878_92947.cc: + Likewise. + * testsuite/23_containers/forward_list/modifiers/92878_92947.cc: + Likewise. + * testsuite/23_containers/list/modifiers/emplace/92878_92947.cc: + Likewise. + * testsuite/23_containers/map/modifiers/emplace/92878_92947.cc: + Likewise. + * testsuite/23_containers/multimap/modifiers/emplace/92878_92947.cc: + Likewise. + * testsuite/23_containers/multiset/modifiers/emplace/92878_92947.cc: + Likewise. + * testsuite/23_containers/priority_queue/92878_92947.cc: Likewise. + * testsuite/23_containers/queue/92878_92947.cc: Likewise. + * testsuite/23_containers/set/modifiers/emplace/92878_92947.cc: + Likewise. + * testsuite/23_containers/stack/92878_92947.cc: Likewise. + * testsuite/23_containers/unordered_map/modifiers/92878_92947.cc: + Likewise. + * testsuite/23_containers/unordered_multimap/modifiers/92878_92947.cc: + Likewise. + * testsuite/23_containers/unordered_multiset/modifiers/92878_92947.cc: + Likewise. + * testsuite/23_containers/unordered_set/modifiers/92878_92947.cc: + Likewise. + * testsuite/23_containers/vector/modifiers/emplace/92878_92947.cc: + Likewise. + 2020-03-28 Jonathan Wakely * testsuite/20_util/is_constructible/value-2.cc: Fix test to account diff --git a/libstdc++-v3/testsuite/20_util/allocator_traits/members/92878_92947.cc b/libstdc++-v3/testsuite/20_util/allocator_traits/members/92878_92947.cc new file mode 100644 index 00000000000..f84d0f7467e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator_traits/members/92878_92947.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + aggressive_aggregate x; + std::allocator a; + using traits = std::allocator_traits>; + traits::destroy(a, &x); + traits::construct(a, &x, 1, 2); + VERIFY(x.a == 1); + VERIFY(x.b == 2); + traits::destroy(a, &x); + traits::construct(a, &x, 1); + VERIFY(x.a == 1); + VERIFY(x.b == 0); + traits::destroy(a, &x); + traits::construct(a, &x); + VERIFY(x.a == 0); + VERIFY(x.b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/any/assign/92878_92947.cc b/libstdc++-v3/testsuite/20_util/any/assign/92878_92947.cc new file mode 100644 index 00000000000..49f05ee28ec --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/any/assign/92878_92947.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + std::any x; + x.emplace(1, 2); + VERIFY(std::any_cast(x).a == 1); + VERIFY(std::any_cast(x).b == 2); + x.emplace(1); + VERIFY(std::any_cast(x).a == 1); + VERIFY(std::any_cast(x).b == 0); + x.emplace(); + VERIFY(std::any_cast(x).a == 0); + VERIFY(std::any_cast(x).b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/any/cons/92878_92947.cc b/libstdc++-v3/testsuite/20_util/any/cons/92878_92947.cc new file mode 100644 index 00000000000..fa8aa2ff1cd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/any/cons/92878_92947.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + std::any x{std::in_place_type, 1, 2}; + VERIFY(std::any_cast(x).a == 1); + VERIFY(std::any_cast(x).b == 2); + std::any y{std::in_place_type, 1}; + VERIFY(std::any_cast(y).a == 1); + VERIFY(std::any_cast(y).b == 0); + std::any z{std::in_place_type}; + VERIFY(std::any_cast(z).a == 0); + VERIFY(std::any_cast(z).b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/is_constructible/92878_92947.cc b/libstdc++-v3/testsuite/20_util/is_constructible/92878_92947.cc new file mode 100644 index 00000000000..567f9be6b9b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_constructible/92878_92947.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +struct vicious_variation +{ + int a; + int b = 42; +}; + +void test01() +{ + static_assert(std::is_constructible_v); + static_assert(std::is_constructible_v); + static_assert(std::is_constructible_v); + static_assert(std::is_default_constructible_v); + static_assert(std::is_trivially_default_constructible_v< + aggressive_aggregate>); + static_assert(std::is_constructible_v); + static_assert(std::is_constructible_v); + static_assert(std::is_constructible_v); + static_assert(std::is_default_constructible_v); + static_assert(!std::is_trivially_default_constructible_v< + vicious_variation>); +} diff --git a/libstdc++-v3/testsuite/20_util/optional/assignment/92878_92947.cc b/libstdc++-v3/testsuite/20_util/optional/assignment/92878_92947.cc new file mode 100644 index 00000000000..a5b74a2ce17 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/optional/assignment/92878_92947.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + std::optional x; + x.emplace(1, 2); + VERIFY(x->a == 1); + VERIFY(x->b == 2); + x.emplace(1); + VERIFY(x->a == 1); + VERIFY(x->b == 0); + x.emplace(); + VERIFY(x->a == 0); + VERIFY(x->b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/optional/cons/92878_92947.cc b/libstdc++-v3/testsuite/20_util/optional/cons/92878_92947.cc new file mode 100644 index 00000000000..52941e7e1f0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/optional/cons/92878_92947.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + std::optional x{std::in_place, 1, 2}; + VERIFY(x->a == 1); + VERIFY(x->b == 2); + std::optional y{std::in_place, 1}; + VERIFY(y->a == 1); + VERIFY(y->b == 0); + std::optional z{std::in_place}; + VERIFY(z->a == 0); + VERIFY(z->b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/pair/cons/92878_92947.cc b/libstdc++-v3/testsuite/20_util/pair/cons/92878_92947.cc new file mode 100644 index 00000000000..ebc4e430f45 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/cons/92878_92947.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + std::pair x{std::piecewise_construct, + std::tuple{1, 2}, std::tuple{42}}; + VERIFY(x.first.a == 1); + VERIFY(x.first.b == 2); + std::pair y{std::piecewise_construct, + std::tuple{1}, std::tuple{42}}; + VERIFY(y.first.a == 1); + VERIFY(y.first.b == 0); + std::pair z{std::piecewise_construct, + std::tuple{}, std::tuple{42}}; + VERIFY(z.first.a == 0); + VERIFY(z.first.b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/92878_92947.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/92878_92947.cc new file mode 100644 index 00000000000..81a938212d6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/92878_92947.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + auto x = std::make_shared(1, 2); + VERIFY(x->a == 1); + VERIFY(x->b == 2); + auto y = std::make_shared(1); + VERIFY(y->a == 1); + VERIFY(y->b == 0); + auto z = std::make_shared(); + VERIFY(z->a == 0); + VERIFY(z->b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/92878_92947.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/92878_92947.cc new file mode 100644 index 00000000000..ac22cefdd04 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/92878_92947.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + aggressive_aggregate x; + std::destroy_at(&x); + std::construct_at(&x, 1, 2); + VERIFY(x.a == 1); + VERIFY(x.b == 2); + std::destroy_at(&x); + std::construct_at(&x, 1); + VERIFY(x.a == 1); + VERIFY(x.b == 0); + std::destroy_at(&x); + std::construct_at(&x); + VERIFY(x.a == 0); + VERIFY(x.b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/creation/92878_92947.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/creation/92878_92947.cc new file mode 100644 index 00000000000..f84e7353d15 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/creation/92878_92947.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + auto x = std::make_unique(1, 2); + VERIFY(x->a == 1); + VERIFY(x->b == 2); + auto y = std::make_unique(1); + VERIFY(y->a == 1); + VERIFY(y->b == 0); + auto z = std::make_unique(); + VERIFY(z->a == 0); + VERIFY(z->b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/92878_92947.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/92878_92947.cc new file mode 100644 index 00000000000..196d0a041a6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/92878_92947.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_make_obj_using_allocator() +{ + std::allocator a; + auto x = + std::make_obj_using_allocator(a, 1, 2); + VERIFY(x.a == 1); + VERIFY(x.b == 2); + x = std::make_obj_using_allocator(a, 1); + VERIFY(x.a == 1); + VERIFY(x.b == 0); + x = std::make_obj_using_allocator(a); + VERIFY(x.a == 0); + VERIFY(x.b == 0); +} + +void test_uninitialized_construct_using_allocator() +{ + std::allocator a; + aggressive_aggregate x; + std::destroy_at(&x); + std::uninitialized_construct_using_allocator(&x, a, 1, 2); + VERIFY(x.a == 1); + VERIFY(x.b == 2); + std::destroy_at(&x); + std::uninitialized_construct_using_allocator(&x, a, 1); + VERIFY(x.a == 1); + VERIFY(x.b == 0); + std::destroy_at(&x); + std::uninitialized_construct_using_allocator(&x, a); + VERIFY(x.a == 0); + VERIFY(x.b == 0); +} + +int main() +{ + test_make_obj_using_allocator(); + test_uninitialized_construct_using_allocator(); +} diff --git a/libstdc++-v3/testsuite/20_util/variant/92878_92947.cc b/libstdc++-v3/testsuite/20_util/variant/92878_92947.cc new file mode 100644 index 00000000000..48bad9feff6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/variant/92878_92947.cc @@ -0,0 +1,91 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +struct dumbo +{ + dumbo() = delete; +}; + +void test_emplace() +{ + std::variant x; + x.emplace(1, 2); + VERIFY(x.index() == 0); + VERIFY(std::get<0>(x).a == 1); + VERIFY(std::get<0>(x).b == 2); + x.emplace(1); + VERIFY(x.index() == 0); + VERIFY(std::get<0>(x).a == 1); + VERIFY(std::get<0>(x).b == 0); + x.emplace(); + VERIFY(x.index() == 0); + VERIFY(std::get<0>(x).a == 0); + VERIFY(std::get<0>(x).b == 0); +} + +void test_in_place_type_construct() +{ + using Var = std::variant; + Var x{std::in_place_type, 1,2}; + VERIFY(x.index() == 0); + VERIFY(std::get<0>(x).a == 1); + VERIFY(std::get<0>(x).b == 2); + Var y{std::in_place_type, 1}; + VERIFY(y.index() == 0); + VERIFY(std::get<0>(y).a == 1); + VERIFY(std::get<0>(y).b == 0); + Var z{std::in_place_type}; + VERIFY(z.index() == 0); + VERIFY(std::get<0>(z).a == 0); + VERIFY(std::get<0>(z).b == 0); +} + +void test_in_place_index_construct() +{ + using Var = std::variant; + Var x{std::in_place_index<0>, 1,2}; + VERIFY(x.index() == 0); + VERIFY(std::get<0>(x).a == 1); + VERIFY(std::get<0>(x).b == 2); + Var y{std::in_place_index<0>, 1}; + VERIFY(y.index() == 0); + VERIFY(std::get<0>(y).a == 1); + VERIFY(std::get<0>(y).b == 0); + Var z{std::in_place_index<0>}; + VERIFY(z.index() == 0); + VERIFY(std::get<0>(z).a == 0); + VERIFY(std::get<0>(z).b == 0); +} + +int main() +{ + test_emplace(); + test_in_place_type_construct(); + test_in_place_index_construct(); +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/92878_92947.cc new file mode 100644 index 00000000000..3dc75db602e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/92878_92947.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_emplace_front() +{ + std::deque x; + x.emplace_front(1, 2); + VERIFY(x.front().a == 1); + VERIFY(x.front().b == 2); + x.emplace_front(1); + VERIFY(x.front().a == 1); + VERIFY(x.front().b == 0); + x.emplace_front(); + VERIFY(x.front().a == 0); + VERIFY(x.front().b == 0); +} + +void test_emplace_back() +{ + std::deque x; + x.emplace_back(1, 2); + VERIFY(x.back().a == 1); + VERIFY(x.back().b == 2); + x.emplace_back(1); + VERIFY(x.back().a == 1); + VERIFY(x.back().b == 0); + x.emplace_back(); + VERIFY(x.back().a == 0); + VERIFY(x.back().b == 0); +} + +int main() +{ + test_emplace_front(); + test_emplace_back(); +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/92878_92947.cc new file mode 100644 index 00000000000..874b9f52982 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/92878_92947.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_emplace_front() +{ + std::forward_list x; + x.emplace_front(1, 2); + VERIFY(x.front().a == 1); + VERIFY(x.front().b == 2); + x.emplace_front(1); + VERIFY(x.front().a == 1); + VERIFY(x.front().b == 0); + x.emplace_front(); + VERIFY(x.front().a == 0); + VERIFY(x.front().b == 0); +} + +void test_emplace_after() +{ + std::forward_list x{{42, 666}}; + auto y = x.emplace_after(x.begin(), 1, 2); + VERIFY(y->a == 1); + VERIFY(y->b == 2); + y = x.emplace_after(x.begin(), 1); + VERIFY(y->a == 1); + VERIFY(y->b == 0); + y = x.emplace_after(x.begin()); + VERIFY(y->a == 0); + VERIFY(y->b == 0); +} + +int main() +{ + test_emplace_front(); + test_emplace_after(); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/92878_92947.cc new file mode 100644 index 00000000000..eb1e9f3525e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/92878_92947.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_emplace_front() +{ + std::list x; + x.emplace_front(1, 2); + VERIFY(x.front().a == 1); + VERIFY(x.front().b == 2); + x.emplace_front(1); + VERIFY(x.front().a == 1); + VERIFY(x.front().b == 0); + x.emplace_front(); + VERIFY(x.front().a == 0); + VERIFY(x.front().b == 0); +} + +void test_emplace_back() +{ + std::list x; + x.emplace_back(1, 2); + VERIFY(x.back().a == 1); + VERIFY(x.back().b == 2); + x.emplace_back(1); + VERIFY(x.back().a == 1); + VERIFY(x.back().b == 0); + x.emplace_back(); + VERIFY(x.back().a == 0); + VERIFY(x.back().b == 0); +} + +void test_emplace() +{ + std::list x{{42, 666}}; + auto y = x.emplace(x.begin(), 1, 2); + VERIFY(y->a == 1); + VERIFY(y->b == 2); + y = x.emplace(x.begin(), 1); + VERIFY(y->a == 1); + VERIFY(y->b == 0); + y = x.emplace(x.begin()); + VERIFY(y->a == 0); + VERIFY(y->b == 0); +} + + +int main() +{ + test_emplace_front(); + test_emplace_back(); + test_emplace(); +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/emplace/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/emplace/92878_92947.cc new file mode 100644 index 00000000000..648a5255c5a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/emplace/92878_92947.cc @@ -0,0 +1,137 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_emplace() +{ + std::map x; + auto emplaced = x.emplace(std::piecewise_construct, + std::tuple(0), std::tuple(1, 2)); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 2); + emplaced = x.emplace(std::piecewise_construct, + std::tuple(1), std::tuple(1)); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 0); + emplaced = x.emplace(std::piecewise_construct, + std::tuple(2), std::tuple()); + VERIFY(emplaced.first->second.a == 0); + VERIFY(emplaced.first->second.b == 0); +} + +void test_emplace_hint() +{ + std::map x; + auto it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(3), std::tuple(1, 2)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(4), std::tuple(1)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(5), std::tuple()); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +void test_try_emplace_rvalue() +{ + std::map x; + auto emplaced = x.try_emplace(6, 1, 2); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 2); + emplaced = x.try_emplace(7, 1); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 0); + emplaced = x.try_emplace(8); + VERIFY(emplaced.first->second.a == 0); + VERIFY(emplaced.first->second.b == 0); +} + +void test_try_emplace_lvalue() +{ + std::map x; + int key = 9; + auto emplaced = x.try_emplace(key, 1, 2); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 2); + key = 10; + emplaced = x.try_emplace(key, 1); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 0); + key = 11; + emplaced = x.try_emplace(key); + VERIFY(emplaced.first->second.a == 0); + VERIFY(emplaced.first->second.b == 0); +} + +void test_try_emplace_hint_rvalue() +{ + std::map x; + auto it = x.try_emplace(x.begin(), 12, 1, 2); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + it = x.try_emplace(x.begin(), 13, 1); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + it = x.try_emplace(x.begin(), 14); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +void test_try_emplace_hint_lvalue() +{ + std::map x; + int key = 15; + auto it = x.try_emplace(x.begin(), key, 1, 2); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + key = 16; + it = x.try_emplace(x.begin(), key, 1); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + key = 17; + it = x.try_emplace(x.begin(), key); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_hint(); + test_try_emplace_rvalue(); + test_try_emplace_lvalue(); + test_try_emplace_hint_rvalue(); + test_try_emplace_hint_lvalue(); +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/emplace/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/emplace/92878_92947.cc new file mode 100644 index 00000000000..9ded6631a23 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/emplace/92878_92947.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_emplace() +{ + std::multimap x; + auto it = x.emplace(std::piecewise_construct, + std::tuple(0), std::tuple(1, 2)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + it = x.emplace(std::piecewise_construct, + std::tuple(1), std::tuple(1)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + it = x.emplace(std::piecewise_construct, + std::tuple(2), std::tuple()); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +void test_emplace_hint() +{ + std::multimap x; + auto it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(3), std::tuple(1, 2)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(4), std::tuple(1)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(5), std::tuple()); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_hint(); +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/emplace/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/emplace/92878_92947.cc new file mode 100644 index 00000000000..85df09908d5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/emplace/92878_92947.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +bool operator<(const aggressive_aggregate& a, + const aggressive_aggregate& b) +{ + return a.a < b.a; +}; + +void test_emplace() +{ + std::multiset x; + auto it = x.emplace(1, 2); + VERIFY(it->a == 1); + VERIFY(it->b == 2); + it = x.emplace(2); + VERIFY(it->a == 2); + VERIFY(it->b == 0); + it = x.emplace(); + VERIFY(it->a == 0); + VERIFY(it->b == 0); +} + +void test_emplace_hint() +{ + std::multiset x; + auto it = x.emplace_hint(x.begin(), + 3, 2); + VERIFY(it->a == 3); + VERIFY(it->b == 2); + it = x.emplace_hint(x.begin(), + 4); + VERIFY(it->a == 4); + VERIFY(it->b == 0); + it = x.emplace_hint(x.begin()); + VERIFY(it->a == 0); + VERIFY(it->b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_hint(); +} diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/92878_92947.cc new file mode 100644 index 00000000000..1111f8ce35a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/92878_92947.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +bool operator<(const aggressive_aggregate& a, const aggressive_aggregate& b) +{ + return a.a < b.a; +} + +void test01() +{ + std::priority_queue x; + x.emplace(); + VERIFY(x.top().a == 0); + VERIFY(x.top().b == 0); + x.emplace(1, 2); + VERIFY(x.top().a == 1); + VERIFY(x.top().b == 2); + x.emplace(2); + VERIFY(x.top().a == 2); + VERIFY(x.top().b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/queue/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/queue/92878_92947.cc new file mode 100644 index 00000000000..e328b36440a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/queue/92878_92947.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + std::queue x; + x.emplace(1, 2); + VERIFY(x.back().a == 1); + VERIFY(x.back().b == 2); + x.emplace(1); + VERIFY(x.back().a == 1); + VERIFY(x.back().b == 0); + x.emplace(); + VERIFY(x.back().a == 0); + VERIFY(x.back().b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/emplace/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/emplace/92878_92947.cc new file mode 100644 index 00000000000..8183b50ec36 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/emplace/92878_92947.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +bool operator<(const aggressive_aggregate& a, + const aggressive_aggregate& b) +{ + return a.a < b.a; +}; + +void test_emplace() +{ + std::set x; + auto emplaced = x.emplace(1, 2); + VERIFY(emplaced.first->a == 1); + VERIFY(emplaced.first->b == 2); + emplaced = x.emplace(2); + VERIFY(emplaced.first->a == 2); + VERIFY(emplaced.first->b == 0); + emplaced = x.emplace(); + VERIFY(emplaced.first->a == 0); + VERIFY(emplaced.first->b == 0); +} + +void test_emplace_hint() +{ + std::set x; + auto it = x.emplace_hint(x.begin(), + 3, 2); + VERIFY(it->a == 3); + VERIFY(it->b == 2); + it = x.emplace_hint(x.begin(), + 4); + VERIFY(it->a == 4); + VERIFY(it->b == 0); + it = x.emplace_hint(x.begin()); + VERIFY(it->a == 0); + VERIFY(it->b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_hint(); +} diff --git a/libstdc++-v3/testsuite/23_containers/stack/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/stack/92878_92947.cc new file mode 100644 index 00000000000..c4522404ecf --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/stack/92878_92947.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test01() +{ + std::stack x; + x.emplace(); + VERIFY(x.top().a == 0); + VERIFY(x.top().b == 0); + x.emplace(1, 2); + VERIFY(x.top().a == 1); + VERIFY(x.top().b == 2); + x.emplace(2); + VERIFY(x.top().a == 2); + VERIFY(x.top().b == 0); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/92878_92947.cc new file mode 100644 index 00000000000..2c8e6ca0831 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/92878_92947.cc @@ -0,0 +1,137 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_emplace() +{ + std::unordered_map x; + auto emplaced = x.emplace(std::piecewise_construct, + std::tuple(0), std::tuple(1, 2)); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 2); + emplaced = x.emplace(std::piecewise_construct, + std::tuple(1), std::tuple(1)); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 0); + emplaced = x.emplace(std::piecewise_construct, + std::tuple(2), std::tuple()); + VERIFY(emplaced.first->second.a == 0); + VERIFY(emplaced.first->second.b == 0); +} + +void test_emplace_hint() +{ + std::unordered_map x; + auto it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(3), std::tuple(1, 2)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(4), std::tuple(1)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(5), std::tuple()); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +void test_try_emplace_rvalue() +{ + std::unordered_map x; + auto emplaced = x.try_emplace(6, 1, 2); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 2); + emplaced = x.try_emplace(7, 1); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 0); + emplaced = x.try_emplace(8); + VERIFY(emplaced.first->second.a == 0); + VERIFY(emplaced.first->second.b == 0); +} + +void test_try_emplace_lvalue() +{ + std::unordered_map x; + int key = 9; + auto emplaced = x.try_emplace(key, 1, 2); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 2); + key = 10; + emplaced = x.try_emplace(key, 1); + VERIFY(emplaced.first->second.a == 1); + VERIFY(emplaced.first->second.b == 0); + key = 11; + emplaced = x.try_emplace(key); + VERIFY(emplaced.first->second.a == 0); + VERIFY(emplaced.first->second.b == 0); +} + +void test_try_emplace_hint_rvalue() +{ + std::unordered_map x; + auto it = x.try_emplace(x.begin(), 12, 1, 2); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + it = x.try_emplace(x.begin(), 13, 1); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + it = x.try_emplace(x.begin(), 14); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +void test_try_emplace_hint_lvalue() +{ + std::unordered_map x; + int key = 15; + auto it = x.try_emplace(x.begin(), key, 1, 2); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + key = 16; + it = x.try_emplace(x.begin(), key, 1); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + key = 17; + it = x.try_emplace(x.begin(), key); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_hint(); + test_try_emplace_rvalue(); + test_try_emplace_lvalue(); + test_try_emplace_hint_rvalue(); + test_try_emplace_hint_lvalue(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/modifiers/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/modifiers/92878_92947.cc new file mode 100644 index 00000000000..4da3c517036 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/modifiers/92878_92947.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_emplace() +{ + std::unordered_multimap x; + auto it = x.emplace(std::piecewise_construct, + std::tuple(0), std::tuple(1, 2)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + it = x.emplace(std::piecewise_construct, + std::tuple(1), std::tuple(1)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + it = x.emplace(std::piecewise_construct, + std::tuple(2), std::tuple()); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +void test_emplace_hint() +{ + std::unordered_multimap x; + auto it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(3), std::tuple(1, 2)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 2); + it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(4), std::tuple(1)); + VERIFY(it->second.a == 1); + VERIFY(it->second.b == 0); + it = x.emplace_hint(x.begin(), + std::piecewise_construct, + std::tuple(5), std::tuple()); + VERIFY(it->second.a == 0); + VERIFY(it->second.b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_hint(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/92878_92947.cc new file mode 100644 index 00000000000..ec0c86e7222 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/92878_92947.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +bool operator==(const aggressive_aggregate& a, + const aggressive_aggregate& b) +{ + return a.a == b.a; +}; + +namespace std { + template<> struct hash { + size_t operator()(const aggressive_aggregate& x) const { + return std::hash()(x.a); + } + }; +} + +void test_emplace() +{ + std::unordered_multiset x; + auto it = x.emplace(1, 2); + VERIFY(it->a == 1); + VERIFY(it->b == 2); + it = x.emplace(2); + VERIFY(it->a == 2); + VERIFY(it->b == 0); + it = x.emplace(); + VERIFY(it->a == 0); + VERIFY(it->b == 0); +} + +void test_emplace_hint() +{ + std::unordered_multiset x; + auto it = x.emplace_hint(x.begin(), + 3, 2); + VERIFY(it->a == 3); + VERIFY(it->b == 2); + it = x.emplace_hint(x.begin(), + 4); + VERIFY(it->a == 4); + VERIFY(it->b == 0); + it = x.emplace_hint(x.begin()); + VERIFY(it->a == 0); + VERIFY(it->b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_hint(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/92878_92947.cc new file mode 100644 index 00000000000..447e1a8934d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/92878_92947.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +bool operator==(const aggressive_aggregate& a, + const aggressive_aggregate& b) +{ + return a.a == b.a; +}; + +namespace std { + template<> struct hash { + size_t operator()(const aggressive_aggregate& x) const { + return std::hash()(x.a); + } + }; +} + +void test_emplace() +{ + std::unordered_set x; + auto emplaced = x.emplace(1, 2); + VERIFY(emplaced.first->a == 1); + VERIFY(emplaced.first->b == 2); + emplaced = x.emplace(2); + VERIFY(emplaced.first->a == 2); + VERIFY(emplaced.first->b == 0); + emplaced = x.emplace(); + VERIFY(emplaced.first->a == 0); + VERIFY(emplaced.first->b == 0); +} + +void test_emplace_hint() +{ + std::unordered_set x; + auto it = x.emplace_hint(x.begin(), + 3, 2); + VERIFY(it->a == 3); + VERIFY(it->b == 2); + it = x.emplace_hint(x.begin(), + 4); + VERIFY(it->a == 4); + VERIFY(it->b == 0); + it = x.emplace_hint(x.begin()); + VERIFY(it->a == 0); + VERIFY(it->b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_hint(); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/92878_92947.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/92878_92947.cc new file mode 100644 index 00000000000..a33bf39998b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/92878_92947.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +struct aggressive_aggregate +{ + int a; + int b; +}; + +void test_emplace() +{ + std::vector x{{42, 666}}; + auto y = x.emplace(x.begin(), 1, 2); + VERIFY(y->a == 1); + VERIFY(y->b == 2); + y = x.emplace(x.begin(), 1); + VERIFY(y->a == 1); + VERIFY(y->b == 0); + y = x.emplace(x.begin()); + VERIFY(y->a == 0); + VERIFY(y->b == 0); +} + +void test_emplace_back() +{ + std::vector x; + x.emplace_back(1, 2); + VERIFY(x.back().a == 1); + VERIFY(x.back().b == 2); + x.emplace_back(1); + VERIFY(x.back().a == 1); + VERIFY(x.back().b == 0); + x.emplace_back(); + VERIFY(x.back().a == 0); + VERIFY(x.back().b == 0); +} + +int main() +{ + test_emplace(); + test_emplace_back(); +} -- 2.30.2