summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2010-02-01 13:10:12 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2010-02-01 13:10:12 +0000
commit522030b576d082baf6e9bbda2ef1a34e1b52f291 (patch)
tree128530f0def7d66d7ffa67a25ad568fb55f31215
parentbd0ed080850e2d6ff15a2b0df1e2ac5383a47ca7 (diff)
downloadgcc-522030b576d082baf6e9bbda2ef1a34e1b52f291.tar.gz
2010-02-01 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/forward_list.h (forward_list<>::resize(size_type), forward_list(size_type)): Only declare. * include/bits/forward_list.tcc (forward_list<>::resize(size_type), forward_list(size_type)): Define, don't assume CopyConstructible. * testsuite/23_containers/forward_list/cons/10.cc: New. * testsuite/23_containers/forward_list/modifiers/6.cc: Likewis. * testsuite/23_containers/forward_list/requirements/dr438/ assign_neg.cc: Adjust dg-error line numbers. * testsuite/23_containers/forward_list/requirements/dr438/ insert_neg.cc: Likewise. * testsuite/23_containers/forward_list/requirements/dr438/ constructor_1_neg.cc: Likewise. * testsuite/23_containers/forward_list/requirements/dr438/ constructor_2_neg.cc: Likewise. * include/bits/forward_list.h: Use _M_get_Node_allocator throughout. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156426 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog19
-rw-r--r--libstdc++-v3/include/bits/forward_list.h26
-rw-r--r--libstdc++-v3/include/bits/forward_list.tcc37
-rw-r--r--libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc50
-rw-r--r--libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc53
-rw-r--r--libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc2
-rw-r--r--libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc2
-rw-r--r--libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc2
-rw-r--r--libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc2
9 files changed, 173 insertions, 20 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index e9dc874e126..a3e0a424963 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,22 @@
+2010-02-01 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/forward_list.h (forward_list<>::resize(size_type),
+ forward_list(size_type)): Only declare.
+ * include/bits/forward_list.tcc (forward_list<>::resize(size_type),
+ forward_list(size_type)): Define, don't assume CopyConstructible.
+ * testsuite/23_containers/forward_list/cons/10.cc: New.
+ * testsuite/23_containers/forward_list/modifiers/6.cc: Likewis.
+ * testsuite/23_containers/forward_list/requirements/dr438/
+ assign_neg.cc: Adjust dg-error line numbers.
+ * testsuite/23_containers/forward_list/requirements/dr438/
+ insert_neg.cc: Likewise.
+ * testsuite/23_containers/forward_list/requirements/dr438/
+ constructor_1_neg.cc: Likewise.
+ * testsuite/23_containers/forward_list/requirements/dr438/
+ constructor_2_neg.cc: Likewise.
+
+ * include/bits/forward_list.h: Use _M_get_Node_allocator throughout.
+
2010-01-31 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/23_containers/array/requirements/exception/
diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h
index b90c8cf6d66..d7005e828c5 100644
--- a/libstdc++-v3/include/bits/forward_list.h
+++ b/libstdc++-v3/include/bits/forward_list.h
@@ -442,17 +442,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ }
/**
- * @brief Creates a %forward_list with copies of the default element
- * type.
+ * @brief Creates a %forward_list with default constructed elements.
* @param n The number of elements to initially create.
*
- * This constructor fills the %forward_list with @a n copies of
- * the default value.
+ * This constructor creates the %forward_list with @a n default
+ * constructed elements.
*/
explicit
- forward_list(size_type __n)
- : _Base()
- { _M_fill_initialize(__n, value_type()); }
+ forward_list(size_type __n);
/**
* @brief Creates a %forward_list with copies of an exemplar element.
@@ -497,7 +494,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* object used by @a list.
*/
forward_list(const forward_list& __list)
- : _Base(__list.get_allocator())
+ : _Base(__list._M_get_Node_allocator())
{ _M_initialize_dispatch(__list.begin(), __list.end(), __false_type()); }
/**
@@ -870,7 +867,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
iterator
insert_after(const_iterator __pos, size_type __n, const _Tp& __val)
{
- forward_list __tmp(__n, __val, this->get_allocator());
+ forward_list __tmp(__n, __val, this->_M_get_Node_allocator());
splice_after(__pos, std::move(__tmp));
return iterator(__const_pointer_cast<typename _Node_base::_Pointer>
(__pos._M_node));
@@ -895,7 +892,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
insert_after(const_iterator __pos,
_InputIterator __first, _InputIterator __last)
{
- forward_list __tmp(__first, __last, this->get_allocator());
+ forward_list __tmp(__first, __last, this->_M_get_Node_allocator());
splice_after(__pos, std::move(__tmp));
return iterator(__const_pointer_cast<typename _Node_base::_Pointer>
(__pos._M_node));
@@ -918,7 +915,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
iterator
insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
{
- forward_list __tmp(__il, this->get_allocator());
+ forward_list __tmp(__il, this->_M_get_Node_allocator());
splice_after(__pos, std::move(__tmp));
return iterator(__const_pointer_cast<typename _Node_base::_Pointer>
(__pos._M_node));
@@ -993,12 +990,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* This function will %resize the %forward_list to the specified
* number of elements. If the number is smaller than the
* %forward_list's current size the %forward_list is truncated,
- * otherwise the %forward_list is extended and new elements are
- * populated with given data.
+ * otherwise the %forward_list is extended and the new elements
+ * are default constructed.
*/
void
- resize(size_type __sz)
- { resize(__sz, _Tp()); }
+ resize(size_type __sz);
/**
* @brief Resizes the %forward_list to the specified number of
diff --git a/libstdc++-v3/include/bits/forward_list.tcc b/libstdc++-v3/include/bits/forward_list.tcc
index 1575cabf1f2..685e533c385 100644
--- a/libstdc++-v3/include/bits/forward_list.tcc
+++ b/libstdc++-v3/include/bits/forward_list.tcc
@@ -1,6 +1,6 @@
// <forward_list.tcc> -*- C++ -*-
-// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010 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
@@ -175,6 +175,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
}
template<typename _Tp, typename _Alloc>
+ forward_list<_Tp, _Alloc>::
+ forward_list(size_type __n)
+ : _Base()
+ {
+ typename _Node_base::_Pointer __to = &this->_M_impl._M_head;
+ for (; __n > 0; --__n)
+ {
+ __to->_M_next = this->_M_create_node();
+ __to = __to->_M_next;
+ }
+ }
+
+ template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>&
forward_list<_Tp, _Alloc>::
operator=(const forward_list& __list)
@@ -204,6 +217,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
+ resize(size_type __sz)
+ {
+ iterator __k = before_begin();
+
+ size_type __len = 0;
+ while (__k._M_next() != end() && __len < __sz)
+ {
+ ++__k;
+ ++__len;
+ }
+ if (__len == __sz)
+ erase_after(__k, end());
+ else
+ {
+ forward_list __tmp(__sz - __len);
+ splice_after(__k, std::move(__tmp));
+ }
+ }
+
+ template<typename _Tp, typename _Alloc>
+ void
+ forward_list<_Tp, _Alloc>::
resize(size_type __sz, value_type __val)
{
iterator __k = before_begin();
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc
new file mode 100644
index 00000000000..4e599dab6bc
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc
@@ -0,0 +1,50 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2010-02-01 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 NoCopyConstructor
+{
+ NoCopyConstructor() : num(-1) { }
+ NoCopyConstructor(const NoCopyConstructor&) = delete;
+
+ operator int() { return num; }
+
+private:
+ int num;
+};
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::forward_list<NoCopyConstructor> fl(5);
+ VERIFY( std::distance(fl.begin(), fl.end()) == 5 );
+ for(auto it = fl.begin(); it != fl.end(); ++it)
+ VERIFY( *it == -1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc
new file mode 100644
index 00000000000..985f592e602
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc
@@ -0,0 +1,53 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2010-02-01 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 NoCopyConstructor
+{
+ NoCopyConstructor() : num(-1) { }
+ NoCopyConstructor(const NoCopyConstructor&) = delete;
+
+ operator int() { return num; }
+
+private:
+ int num;
+};
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::forward_list<NoCopyConstructor> fl;
+ VERIFY( std::distance(fl.begin(), fl.end()) == 0 );
+
+ fl.resize(10);
+ VERIFY( std::distance(fl.begin(), fl.end()) == 10 );
+ for(auto it = fl.begin(); it != fl.end(); ++it)
+ VERIFY( *it == -1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc
index 7e6e6492a2c..5351a5b0788 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc
@@ -1,6 +1,6 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
-// { dg-error "no matching" "" { target *-*-* } 1205 }
+// { dg-error "no matching" "" { target *-*-* } 1201 }
// { dg-excess-errors "" }
// Copyright (C) 2009, 2010 Free Software Foundation
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc
index 439a7b32191..b624ab2356f 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc
@@ -1,6 +1,6 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
-// { dg-error "no matching" "" { target *-*-* } 1205 }
+// { dg-error "no matching" "" { target *-*-* } 1201 }
// { dg-excess-errors "" }
// Copyright (C) 2009, 2010 Free Software Foundation
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc
index 8184b67d750..0a593c83a91 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc
@@ -1,6 +1,6 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
-// { dg-error "no matching" "" { target *-*-* } 1205 }
+// { dg-error "no matching" "" { target *-*-* } 1201 }
// { dg-excess-errors "" }
// Copyright (C) 2009, 2010 Free Software Foundation
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc
index 0bc1a3d58cb..4739ce77f75 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc
@@ -1,6 +1,6 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
-// { dg-error "no matching" "" { target *-*-* } 1205 }
+// { dg-error "no matching" "" { target *-*-* } 1201 }
// { dg-excess-errors "" }
// Copyright (C) 2009, 2010 Free Software Foundation