public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-10240] libstdc++: Improve tests for emplace member of sequence containers
@ 2024-03-18 14:05 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2024-03-18 14:05 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:1bb2bfb5d984456f59b42228f06d4ad4976358e7

commit r12-10240-g1bb2bfb5d984456f59b42228f06d4ad4976358e7
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jun 8 12:19:26 2023 +0100

    libstdc++: Improve tests for emplace member of sequence containers
    
    Our existing tests for std::deque::emplace, std::list::emplace and
    std::vector::emplace are poor. We only have compile tests for PR 52799
    and the equivalent for a const_iterator as the insertion point. This
    fails to check that the value is actually inserted correctly and the
    right iterator is returned.
    
    Add new tests that cover the existing 52799.cc and const_iterator.cc
    compile-only tests, as well as verifying the effects are correct.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/23_containers/deque/modifiers/emplace/52799.cc:
            Removed.
            * testsuite/23_containers/deque/modifiers/emplace/const_iterator.cc:
            Removed.
            * testsuite/23_containers/list/modifiers/emplace/52799.cc:
            Removed.
            * testsuite/23_containers/list/modifiers/emplace/const_iterator.cc:
            Removed.
            * testsuite/23_containers/vector/modifiers/emplace/52799.cc:
            Removed.
            * testsuite/23_containers/vector/modifiers/emplace/const_iterator.cc:
            Removed.
            * testsuite/23_containers/deque/modifiers/emplace/1.cc: New
            test.
            * testsuite/23_containers/list/modifiers/emplace/1.cc: New
            test.
            * testsuite/23_containers/vector/modifiers/emplace/1.cc: New
            test.
    
    (cherry picked from commit 3ec1d76a359542ed4c8370390efa9ee9e25e757f)

Diff:
---
 .../23_containers/deque/modifiers/emplace/1.cc     | 70 +++++++++++++++++++++
 .../23_containers/deque/modifiers/emplace/52799.cc | 27 --------
 .../deque/modifiers/emplace/const_iterator.cc      | 26 --------
 .../23_containers/list/modifiers/emplace/1.cc      | 71 ++++++++++++++++++++++
 .../23_containers/list/modifiers/emplace/52799.cc  | 27 --------
 .../list/modifiers/emplace/const_iterator.cc       | 26 --------
 .../23_containers/vector/modifiers/emplace/1.cc    | 70 +++++++++++++++++++++
 .../vector/modifiers/emplace/52799.cc              | 27 --------
 .../vector/modifiers/emplace/const_iterator.cc     | 26 --------
 9 files changed, 211 insertions(+), 159 deletions(-)

diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/1.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/1.cc
new file mode 100644
index 00000000000..c6b0318e5ea
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/1.cc
@@ -0,0 +1,70 @@
+// { dg-do run { target c++11 } }
+
+#include <deque>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::deque<int> c;
+  std::deque<int>::iterator pos;
+
+  // libstdc++/52799
+  pos = c.emplace(c.begin());
+  VERIFY( c.size() == 1 );
+  VERIFY( c[0] == 0 );
+  VERIFY( pos == c.begin() );
+  pos = c.emplace(c.begin(), 2);
+  VERIFY( c.size() == 2 );
+  VERIFY( c[0] == 2 );
+  VERIFY( c[1] == 0 );
+  VERIFY( pos == c.begin() );
+  pos = c.emplace(c.end(), 3);
+  VERIFY( c.size() == 3 );
+  VERIFY( c[0] == 2 );
+  VERIFY( c[1] == 0 );
+  VERIFY( c[2] == 3 );
+  VERIFY( pos == --c.end() );
+
+  // const_iterator
+  pos = c.emplace(c.cbegin());
+  VERIFY( c.size() == 4 );
+  VERIFY( c[0] == 0 );
+  VERIFY( c[1] == 2 );
+  VERIFY( pos == c.cbegin() );
+  pos = c.emplace(c.cbegin() + 2, 22);
+  VERIFY( c.size() == 5 );
+  VERIFY( c[0] == 0 );
+  VERIFY( c[1] == 2 );
+  VERIFY( c[2] == 22 );
+  VERIFY( pos == c.cbegin() + 2 );
+}
+
+struct V
+{
+  explicit V(int a, int b = 0) : val(a+b) { }
+  int val;
+};
+
+void
+test02()
+{
+  std::deque<V> c;
+  std::deque<V>::iterator pos;
+
+  pos = c.emplace(c.end(), 1);
+  VERIFY( c.size() == 1 );
+  VERIFY( c[0].val == 1 );
+  VERIFY( pos == --c.end() );
+  pos = c.emplace(c.cend(), 2, 3);
+  VERIFY( c.size() == 2 );
+  VERIFY( c[0].val == 1 );
+  VERIFY( c[1].val == 5 );
+  VERIFY( pos == --c.cend() );
+}
+
+int main()
+{
+  test01();
+  test02();
+}
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/52799.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/52799.cc
deleted file mode 100644
index b236fca8db9..00000000000
--- a/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/52799.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-// { dg-do compile { target c++11 } }
-
-// Copyright (C) 2012-2022 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>
-
-// libstdc++/52799
-int main()
-{
-  std::deque<int> d;
-  d.emplace(d.begin());
-}
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/const_iterator.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/const_iterator.cc
deleted file mode 100644
index fe5a63d335c..00000000000
--- a/libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/const_iterator.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// { dg-do compile { target c++11 } }
-
-// Copyright (C) 2013-2022 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>
-
-void test01()
-{
-  std::deque<int> d1;
-  d1.emplace(d1.cbegin(), 1);
-}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/1.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/1.cc
new file mode 100644
index 00000000000..8f14c15d7a1
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/1.cc
@@ -0,0 +1,71 @@
+// { dg-do run { target c++11 } }
+
+#include <list>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::list<int> c;
+  std::list<int>::iterator pos;
+
+  // libstdc++/52799
+  pos = c.emplace(c.begin());
+  VERIFY( c.size() == 1 );
+  VERIFY( *pos == 0 );
+  VERIFY( pos == c.begin() );
+  pos = c.emplace(c.begin(), 2);
+  VERIFY( c.size() == 2 );
+  VERIFY( *pos == 2 );
+  VERIFY( pos == c.begin() );
+  VERIFY( *++pos == 0 );
+  pos = c.emplace(c.end(), 3);
+  VERIFY( c.size() == 3 );
+  VERIFY( *pos == 3 );
+  VERIFY( pos == --c.end() );
+  VERIFY( *--pos == 0 );
+  VERIFY( *--pos == 2 );
+
+  // const_iterator
+  pos = c.emplace(c.cbegin());
+  VERIFY( c.size() == 4 );
+  VERIFY( *pos == 0 );
+  VERIFY( pos == c.cbegin() );
+  VERIFY( *++pos == 2 );
+  std::list<int>::const_iterator i = std::next(c.cbegin(), 2);
+  pos = c.emplace(i, 22);
+  VERIFY( c.size() == 5 );
+  VERIFY( *pos == 22 );
+  VERIFY( pos == std::prev(i) );
+  VERIFY( *--pos == 2 );
+  VERIFY( *--pos == 0 );
+}
+
+struct V
+{
+  explicit V(int a, int b = 0) : val(a+b) { }
+  int val;
+};
+
+void
+test02()
+{
+  std::list<V> c;
+  std::list<V>::iterator pos;
+
+  pos = c.emplace(c.end(), 1);
+  VERIFY( c.size() == 1 );
+  VERIFY( pos->val == 1 );
+  VERIFY( pos == --c.end() );
+  pos = c.emplace(c.cend(), 2, 3);
+  VERIFY( c.size() == 2 );
+  VERIFY( pos->val == 5 );
+  VERIFY( pos == --c.cend() );
+  VERIFY( c.front().val == 1 );
+}
+
+int main()
+{
+  test01();
+  test02();
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/52799.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/52799.cc
deleted file mode 100644
index 3b6c112994c..00000000000
--- a/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/52799.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-// { dg-do compile { target c++11 } }
-
-// Copyright (C) 2012-2022 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>
-
-// libstdc++/52799
-int main()
-{
-  std::list<int> l;
-  l.emplace(l.begin());
-}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/const_iterator.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/const_iterator.cc
deleted file mode 100644
index e060f2b4dde..00000000000
--- a/libstdc++-v3/testsuite/23_containers/list/modifiers/emplace/const_iterator.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// { dg-do compile { target c++11 } }
-
-// Copyright (C) 2013-2022 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>
-
-void test01()
-{
-  std::list<int> l1;
-  l1.emplace(l1.cbegin(), 1);
-}
diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/1.cc
new file mode 100644
index 00000000000..53f3ebe02e4
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/1.cc
@@ -0,0 +1,70 @@
+// { dg-do run { target c++11 } }
+
+#include <vector>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::vector<int> c;
+  std::vector<int>::iterator pos;
+
+  // libstdc++/52799
+  pos = c.emplace(c.begin());
+  VERIFY( c.size() == 1 );
+  VERIFY( c[0] == 0 );
+  VERIFY( pos == c.begin() );
+  pos = c.emplace(c.begin(), 2);
+  VERIFY( c.size() == 2 );
+  VERIFY( c[0] == 2 );
+  VERIFY( c[1] == 0 );
+  VERIFY( pos == c.begin() );
+  pos = c.emplace(c.end(), 3);
+  VERIFY( c.size() == 3 );
+  VERIFY( c[0] == 2 );
+  VERIFY( c[1] == 0 );
+  VERIFY( c[2] == 3 );
+  VERIFY( pos == --c.end() );
+
+  // const_iterator
+  pos = c.emplace(c.cbegin());
+  VERIFY( c.size() == 4 );
+  VERIFY( c[0] == 0 );
+  VERIFY( c[1] == 2 );
+  VERIFY( pos == c.cbegin() );
+  pos = c.emplace(c.cbegin() + 2, 22);
+  VERIFY( c.size() == 5 );
+  VERIFY( c[0] == 0 );
+  VERIFY( c[1] == 2 );
+  VERIFY( c[2] == 22 );
+  VERIFY( pos == c.cbegin() + 2 );
+}
+
+struct V
+{
+  explicit V(int a, int b = 0) : val(a+b) { }
+  int val;
+};
+
+void
+test02()
+{
+  std::vector<V> c;
+  std::vector<V>::iterator pos;
+
+  pos = c.emplace(c.end(), 1);
+  VERIFY( c.size() == 1 );
+  VERIFY( c[0].val == 1 );
+  VERIFY( pos == --c.end() );
+  pos = c.emplace(c.cend(), 2, 3);
+  VERIFY( c.size() == 2 );
+  VERIFY( c[0].val == 1 );
+  VERIFY( c[1].val == 5 );
+  VERIFY( pos == --c.cend() );
+}
+
+int main()
+{
+  test01();
+  test02();
+}
diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/52799.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/52799.cc
deleted file mode 100644
index 7c4524fb495..00000000000
--- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/52799.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-// { dg-do compile { target c++11 } }
-
-// Copyright (C) 2012-2022 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>
-
-// libstdc++/52799
-int main()
-{
-  std::vector<int> v;
-  v.emplace(v.begin());
-}
diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/const_iterator.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/const_iterator.cc
deleted file mode 100644
index 2fdf25e1fbe..00000000000
--- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/emplace/const_iterator.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// { dg-do compile { target c++11 } }
-
-// Copyright (C) 2013-2022 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>
-
-void test01()
-{
-  std::vector<int> v1;
-  v1.emplace(v1.cbegin(), 1);
-}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-18 14:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 14:05 [gcc r12-10240] libstdc++: Improve tests for emplace member of sequence containers Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).