+2020-03-31 Ville Voutilainen <ville.voutilainen@gmail.com>
+
+ 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 <jwakely@redhat.com>
* testsuite/20_util/is_constructible/value-2.cc: Fix test to account
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ aggressive_aggregate x;
+ std::allocator<aggressive_aggregate> a;
+ using traits = std::allocator_traits<std::allocator<aggressive_aggregate>>;
+ 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <any>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ std::any x;
+ x.emplace<aggressive_aggregate>(1, 2);
+ VERIFY(std::any_cast<aggressive_aggregate>(x).a == 1);
+ VERIFY(std::any_cast<aggressive_aggregate>(x).b == 2);
+ x.emplace<aggressive_aggregate>(1);
+ VERIFY(std::any_cast<aggressive_aggregate>(x).a == 1);
+ VERIFY(std::any_cast<aggressive_aggregate>(x).b == 0);
+ x.emplace<aggressive_aggregate>();
+ VERIFY(std::any_cast<aggressive_aggregate>(x).a == 0);
+ VERIFY(std::any_cast<aggressive_aggregate>(x).b == 0);
+}
+
+int main()
+{
+ test01();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <any>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ std::any x{std::in_place_type<aggressive_aggregate>, 1, 2};
+ VERIFY(std::any_cast<aggressive_aggregate>(x).a == 1);
+ VERIFY(std::any_cast<aggressive_aggregate>(x).b == 2);
+ std::any y{std::in_place_type<aggressive_aggregate>, 1};
+ VERIFY(std::any_cast<aggressive_aggregate>(y).a == 1);
+ VERIFY(std::any_cast<aggressive_aggregate>(y).b == 0);
+ std::any z{std::in_place_type<aggressive_aggregate>};
+ VERIFY(std::any_cast<aggressive_aggregate>(z).a == 0);
+ VERIFY(std::any_cast<aggressive_aggregate>(z).b == 0);
+}
+
+int main()
+{
+ test01();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <type_traits>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+struct vicious_variation
+{
+ int a;
+ int b = 42;
+};
+
+void test01()
+{
+ static_assert(std::is_constructible_v<aggressive_aggregate, int, int>);
+ static_assert(std::is_constructible_v<aggressive_aggregate, int>);
+ static_assert(std::is_constructible_v<aggressive_aggregate>);
+ static_assert(std::is_default_constructible_v<aggressive_aggregate>);
+ static_assert(std::is_trivially_default_constructible_v<
+ aggressive_aggregate>);
+ static_assert(std::is_constructible_v<vicious_variation, int, int>);
+ static_assert(std::is_constructible_v<vicious_variation, int>);
+ static_assert(std::is_constructible_v<vicious_variation>);
+ static_assert(std::is_default_constructible_v<vicious_variation>);
+ static_assert(!std::is_trivially_default_constructible_v<
+ vicious_variation>);
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <optional>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ std::optional<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <optional>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ std::optional<aggressive_aggregate> x{std::in_place, 1, 2};
+ VERIFY(x->a == 1);
+ VERIFY(x->b == 2);
+ std::optional<aggressive_aggregate> y{std::in_place, 1};
+ VERIFY(y->a == 1);
+ VERIFY(y->b == 0);
+ std::optional<aggressive_aggregate> z{std::in_place};
+ VERIFY(z->a == 0);
+ VERIFY(z->b == 0);
+}
+
+int main()
+{
+ test01();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ std::pair<aggressive_aggregate, int> x{std::piecewise_construct,
+ std::tuple{1, 2}, std::tuple{42}};
+ VERIFY(x.first.a == 1);
+ VERIFY(x.first.b == 2);
+ std::pair<aggressive_aggregate, int> y{std::piecewise_construct,
+ std::tuple{1}, std::tuple{42}};
+ VERIFY(y.first.a == 1);
+ VERIFY(y.first.b == 0);
+ std::pair<aggressive_aggregate, int> z{std::piecewise_construct,
+ std::tuple{}, std::tuple{42}};
+ VERIFY(z.first.a == 0);
+ VERIFY(z.first.b == 0);
+}
+
+int main()
+{
+ test01();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ auto x = std::make_shared<aggressive_aggregate>(1, 2);
+ VERIFY(x->a == 1);
+ VERIFY(x->b == 2);
+ auto y = std::make_shared<aggressive_aggregate>(1);
+ VERIFY(y->a == 1);
+ VERIFY(y->b == 0);
+ auto z = std::make_shared<aggressive_aggregate>();
+ VERIFY(z->a == 0);
+ VERIFY(z->b == 0);
+}
+
+int main()
+{
+ test01();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ auto x = std::make_unique<aggressive_aggregate>(1, 2);
+ VERIFY(x->a == 1);
+ VERIFY(x->b == 2);
+ auto y = std::make_unique<aggressive_aggregate>(1);
+ VERIFY(y->a == 1);
+ VERIFY(y->b == 0);
+ auto z = std::make_unique<aggressive_aggregate>();
+ VERIFY(z->a == 0);
+ VERIFY(z->b == 0);
+}
+
+int main()
+{
+ test01();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_make_obj_using_allocator()
+{
+ std::allocator<aggressive_aggregate> a;
+ auto x =
+ std::make_obj_using_allocator<aggressive_aggregate>(a, 1, 2);
+ VERIFY(x.a == 1);
+ VERIFY(x.b == 2);
+ x = std::make_obj_using_allocator<aggressive_aggregate>(a, 1);
+ VERIFY(x.a == 1);
+ VERIFY(x.b == 0);
+ x = std::make_obj_using_allocator<aggressive_aggregate>(a);
+ VERIFY(x.a == 0);
+ VERIFY(x.b == 0);
+}
+
+void test_uninitialized_construct_using_allocator()
+{
+ std::allocator<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <variant>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+struct dumbo
+{
+ dumbo() = delete;
+};
+
+void test_emplace()
+{
+ std::variant<aggressive_aggregate, dumbo> x;
+ x.emplace<aggressive_aggregate>(1, 2);
+ VERIFY(x.index() == 0);
+ VERIFY(std::get<0>(x).a == 1);
+ VERIFY(std::get<0>(x).b == 2);
+ x.emplace<aggressive_aggregate>(1);
+ VERIFY(x.index() == 0);
+ VERIFY(std::get<0>(x).a == 1);
+ VERIFY(std::get<0>(x).b == 0);
+ x.emplace<aggressive_aggregate>();
+ 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<aggressive_aggregate, dumbo>;
+ Var x{std::in_place_type<aggressive_aggregate>, 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<aggressive_aggregate>, 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<aggressive_aggregate>};
+ 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<aggressive_aggregate, dumbo>;
+ 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <deque>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_emplace_front()
+{
+ std::deque<aggressive_aggregate> 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<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_emplace_front()
+{
+ std::forward_list<aggressive_aggregate> 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<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <list>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_emplace_front()
+{
+ std::list<aggressive_aggregate> 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<aggressive_aggregate> 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<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <map>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_emplace()
+{
+ std::map<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <map>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_emplace()
+{
+ std::multimap<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <set>
+#include <testsuite_hooks.h>
+
+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<aggressive_aggregate> 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<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <queue>
+#include <testsuite_hooks.h>
+
+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<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <queue>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ std::queue<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <set>
+#include <testsuite_hooks.h>
+
+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<aggressive_aggregate> 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<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <stack>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test01()
+{
+ std::stack<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <unordered_map>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_emplace()
+{
+ std::unordered_map<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <unordered_map>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_emplace()
+{
+ std::unordered_multimap<int, aggressive_aggregate> 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<int, aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <unordered_set>
+#include <testsuite_hooks.h>
+
+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<aggressive_aggregate> {
+ size_t operator()(const aggressive_aggregate& x) const {
+ return std::hash<int>()(x.a);
+ }
+ };
+}
+
+void test_emplace()
+{
+ std::unordered_multiset<aggressive_aggregate> 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<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <unordered_set>
+#include <testsuite_hooks.h>
+
+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<aggressive_aggregate> {
+ size_t operator()(const aggressive_aggregate& x) const {
+ return std::hash<int>()(x.a);
+ }
+ };
+}
+
+void test_emplace()
+{
+ std::unordered_set<aggressive_aggregate> 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<aggressive_aggregate> 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();
+}
--- /dev/null
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+#include <vector>
+#include <testsuite_hooks.h>
+
+struct aggressive_aggregate
+{
+ int a;
+ int b;
+};
+
+void test_emplace()
+{
+ std::vector<aggressive_aggregate> 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<aggressive_aggregate> 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();
+}