From fd8431c84811e14566423cbc55645074300ec2fa Mon Sep 17 00:00:00 2001 From: bkoz Date: Fri, 22 Oct 2004 05:32:16 +0000 Subject: [PATCH] 2004-10-21 Benjamin Kosnik * include/tr1/array (array): Make safe for zero-sized arrays. (array::end): Return one past the end. (array::at): Use __throw_out_of_range, include functexcept.h. (operator==): Implement. (operator!=): Same. (operator<): Same. (operator>): Same. (operator>=): Same. (operator<=): Same. * testsuite/tr1/6_containers/array/capacity/(empty.cc, max_size.cc, size.cc): New. * testsuite/tr1/6_containers/array/comparison_operators/(equal.cc, greater.cc, greater_or_equal.cc, less.cc, less_or_equal.cc, not_equal): New. * testsuite/tr1/6_containers/array/cons/aggregate_initialization.cc: New. * testsuite/tr1/6_containers/array/element_access/at_out_of_range.cc: New. * testsuite/tr1/6_containers/array/iterators/end_is_one_past.cc: New. * testsuite/tr1/6_containers/array/requirements/(contiguous.cc, instantiate, typedefs, zero_size_arrays): New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89429 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 24 +++++++++ libstdc++-v3/include/bits/locale_facets.tcc | 2 +- libstdc++-v3/include/tr1/array | 48 +++++++++-------- .../tr1/6_containers/array/capacity/empty.cc | 53 +++++++++++++++++++ .../tr1/6_containers/array/capacity/max_size.cc | 53 +++++++++++++++++++ .../tr1/6_containers/array/capacity/size.cc | 53 +++++++++++++++++++ .../array/comparison_operators/equal.cc | 45 ++++++++++++++++ .../array/comparison_operators/greater.cc | 45 ++++++++++++++++ .../array/comparison_operators/greater_or_equal.cc | 45 ++++++++++++++++ .../array/comparison_operators/less.cc | 45 ++++++++++++++++ .../array/comparison_operators/less_or_equal.cc | 45 ++++++++++++++++ .../array/comparison_operators/not_equal.cc | 45 ++++++++++++++++ .../array/cons/aggregate_initialization.cc | 41 +++++++++++++++ .../array/element_access/at_out_of_range.cc | 54 +++++++++++++++++++ .../array/iterators/end_is_one_past.cc | 46 ++++++++++++++++ .../6_containers/array/requirements/contiguous.cc | 46 ++++++++++++++++ .../6_containers/array/requirements/instantiate.cc | 36 +++++++++++++ .../6_containers/array/requirements/typedefs.cc | 49 +++++++++++++++++ .../array/requirements/zero_sized_arrays.cc | 61 ++++++++++++++++++++++ 19 files changed, 812 insertions(+), 24 deletions(-) create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/capacity/empty.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/capacity/max_size.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/capacity/size.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/equal.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater_or_equal.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less_or_equal.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/not_equal.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/cons/aggregate_initialization.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/element_access/at_out_of_range.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/iterators/end_is_one_past.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/requirements/contiguous.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/requirements/instantiate.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/requirements/typedefs.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/array/requirements/zero_sized_arrays.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a9a8d211364..ac70fd7140b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,27 @@ +2004-10-21 Benjamin Kosnik + + * include/tr1/array (array): Make safe for zero-sized arrays. + (array::end): Return one past the end. + (array::at): Use __throw_out_of_range, include functexcept.h. + (operator==): Implement. + (operator!=): Same. + (operator<): Same. + (operator>): Same. + (operator>=): Same. + (operator<=): Same. + * testsuite/tr1/6_containers/array/capacity/(empty.cc, + max_size.cc, size.cc): New. + * testsuite/tr1/6_containers/array/comparison_operators/(equal.cc, + greater.cc, greater_or_equal.cc, less.cc, less_or_equal.cc, + not_equal): New. + * testsuite/tr1/6_containers/array/cons/aggregate_initialization.cc: + New. + * testsuite/tr1/6_containers/array/element_access/at_out_of_range.cc: + New. + * testsuite/tr1/6_containers/array/iterators/end_is_one_past.cc: New. + * testsuite/tr1/6_containers/array/requirements/(contiguous.cc, + instantiate, typedefs, zero_size_arrays): New. + 2004-10-21 Paolo Carlini Benjamin Kosnik diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 141138ba2fb..9058dd617b1 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -2079,7 +2079,7 @@ namespace std const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); const char_type* __dates[2]; __tp._M_date_formats(__dates); - __beg = _M_extract_via_format(__beg, __end, __io, __err, + __beg = _M_extract_via_format(__beg, __end, __io, __err, __tm, __dates[0]); if (__beg == __end) __err |= ios_base::eofbit; diff --git a/libstdc++-v3/include/tr1/array b/libstdc++-v3/include/tr1/array index 7f092ad4852..d355285f56e 100644 --- a/libstdc++-v3/include/tr1/array +++ b/libstdc++-v3/include/tr1/array @@ -32,6 +32,8 @@ #include #include +#include +#include //namespace std::tr1 namespace std @@ -40,12 +42,9 @@ namespace tr1 { // [6.2.2] Class template array template // Requires complete type _Tp. - // Use of char array allows _Tp to skirt default constructable requirement. template struct array { - enum { _S_index = _Nm }; - typedef _Tp value_type; typedef value_type& reference; typedef const value_type& const_reference; @@ -56,7 +55,11 @@ namespace tr1 typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - value_type _M_instance[_Nm]; + // Compile time constant without other dependencies. + enum { _S_index = _Nm }; + + // Support for zero-sized arrays mandatory. + value_type _M_instance[_Nm ? _Nm : 1]; // No explicit construct/copy/destroy for aggregate type. @@ -77,11 +80,11 @@ namespace tr1 iterator end() - { return reinterpret_cast(&_M_instance[_S_index - 1]); } + { return reinterpret_cast(&_M_instance[_Nm]); } const_iterator end() const - { return reinterpret_cast(&_M_instance[_S_index - 1]); } + { return reinterpret_cast(&_M_instance[_Nm]); } reverse_iterator rbegin() @@ -101,17 +104,13 @@ namespace tr1 // Capacity. size_type - size() const { return _S_index; } + size() const { return _Nm; } size_type - max_size() const - { - // XXX Not specified. Unnecessary, this is fixed-size. - return _S_index; - } + max_size() const { return _Nm; } bool - empty() const; + empty() const { return size() == 0; } // Element access. reference @@ -125,16 +124,16 @@ namespace tr1 const_reference at(size_type __n) const { - if (__builtin_expect(__n > _S_index, false)) - throw std::bad_alloc(); + if (__builtin_expect(__n > _Nm, false)) + std::__throw_out_of_range("array::at"); return reinterpret_cast(_M_instance[__n]); } reference at(size_type __n) { - if (__builtin_expect(__n > _S_index, false)) - throw std::bad_alloc(); + if (__builtin_expect(__n > _Nm, false)) + std::__throw_out_of_range("array::at"); return reinterpret_cast(_M_instance[__n]); } @@ -161,7 +160,7 @@ namespace tr1 template bool operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + { return std::equal(__one.begin(), __one.end(), __two.begin()); } template bool @@ -170,23 +169,26 @@ namespace tr1 template bool - operator<(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + operator<(const array<_Tp, _Nm>& a, const array<_Tp, _Nm>& b) + { + return std::lexicographical_compare(a.begin(), a.end(), + b.begin(), b.end()); + } template bool operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + { return __two < __one; } template bool operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + { return !(__one > __two); } template bool operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + { return !(__one < __two); } // [6.2.2.2] Specialized algorithms. template diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/empty.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/empty.cc new file mode 100644 index 00000000000..844ca5a7f54 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/empty.cc @@ -0,0 +1,53 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + { + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + + VERIFY( a.empty() == false ); + } + + { + const size_t len = 0; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a; + + VERIFY( a.empty() == true ); + } +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/max_size.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/max_size.cc new file mode 100644 index 00000000000..d081b3daa87 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/max_size.cc @@ -0,0 +1,53 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + { + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + + VERIFY( a.size() == len ); + } + + { + const size_t len = 0; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a; + + VERIFY( a.size() == len ); + } +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/size.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/size.cc new file mode 100644 index 00000000000..d081b3daa87 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/size.cc @@ -0,0 +1,53 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + { + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + + VERIFY( a.size() == len ); + } + + { + const size_t len = 0; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a; + + VERIFY( a.size() == len ); + } +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/equal.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/equal.cc new file mode 100644 index 00000000000..0ace9aec0df --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/equal.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + array_type b = { 0, 1, 2, 3, 4 }; + array_type c = { 0, 1, 2, 3 }; + + VERIFY( a == b ); + VERIFY( !(a == c) ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater.cc new file mode 100644 index 00000000000..3badc2033e6 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + array_type b = { 0, 1, 2, 3, 4 }; + array_type c = { 0, 1, 2, 3, 7 }; + + VERIFY( !(a > b) ); + VERIFY( c > a ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater_or_equal.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater_or_equal.cc new file mode 100644 index 00000000000..aaf0cb06fbe --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater_or_equal.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + array_type b = { 0, 1, 2, 3, 4 }; + array_type c = { 0, 1, 2, 3, 7 }; + + VERIFY( a >= b ); + VERIFY( c >= a ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less.cc new file mode 100644 index 00000000000..c0debec764f --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + array_type b = { 0, 1, 2, 3, 4 }; + array_type c = { 0, 1, 2, 3, 7 }; + + VERIFY( !(a < b) ); + VERIFY( a < c ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less_or_equal.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less_or_equal.cc new file mode 100644 index 00000000000..11ae4e8514c --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less_or_equal.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + array_type b = { 0, 1, 2, 3, 4 }; + array_type c = { 0, 1, 2, 3, 7 }; + + VERIFY( a <= b ); + VERIFY( a <= c ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/not_equal.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/not_equal.cc new file mode 100644 index 00000000000..f166ae74873 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/not_equal.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + array_type b = { 0, 1, 2, 3, 4 }; + array_type c = { 0, 1, 2, 3 }; + + VERIFY( !(a != b) ); + VERIFY( a != c ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/cons/aggregate_initialization.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/cons/aggregate_initialization.cc new file mode 100644 index 00000000000..f885424b6aa --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/cons/aggregate_initialization.cc @@ -0,0 +1,41 @@ +// { dg-do compile } + +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include + +void +test01() +{ + typedef std::tr1::array array_type; + + array_type a = { 0, 1, 2, 3, 4 }; + array_type b = { 0, 1, 2, 3 }; +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/element_access/at_out_of_range.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/element_access/at_out_of_range.cc new file mode 100644 index 00000000000..1b178565296 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/element_access/at_out_of_range.cc @@ -0,0 +1,54 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + + try + { + a.at(len); + } + catch(std::out_of_range& obj) + { + // Expected. + } + catch(...) + { + // Failed. + throw; + } +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/iterators/end_is_one_past.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/iterators/end_is_one_past.cc new file mode 100644 index 00000000000..890704fb8ed --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/iterators/end_is_one_past.cc @@ -0,0 +1,46 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + + array_type::iterator b = a.begin(); + array_type::iterator e = a.end(); + + VERIFY( e != (b + a.size() - 1)); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/contiguous.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/contiguous.cc new file mode 100644 index 00000000000..2643600f431 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/contiguous.cc @@ -0,0 +1,46 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2 Class template array + +#include +#include + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + array_type a = { 0, 1, 2, 3, 4 }; + + // &a[n] == &a[0] + n for all 0 <= n < N. + for (size_t i = 0; i < len; ++i) + { + VERIFY( &a[i] == &a[0] + i ); + } +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/instantiate.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/instantiate.cc new file mode 100644 index 00000000000..f4d7b68b422 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/instantiate.cc @@ -0,0 +1,36 @@ +// { dg-do compile } + +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// 6.2.2 Class template array + +#include + +template class std::tr1::array; diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/typedefs.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/typedefs.cc new file mode 100644 index 00000000000..225426d54b3 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/typedefs.cc @@ -0,0 +1,49 @@ +// { dg-do compile } + +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// 6.2.2 Class template array + +#include + +void test01() +{ + // Check for required typedefs + typedef std::tr1::array test_type; + typedef test_type::reference reference; + typedef test_type::const_reference const_reference; + typedef test_type::iterator iterator; + typedef test_type::const_iterator const_iterator; + typedef test_type::size_type size_type; + typedef test_type::difference_type difference_type; + typedef test_type::value_type value_type; + typedef test_type::reverse_iterator reverse_iterator; + typedef test_type::const_reverse_iterator const_reverse_iterator; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/zero_sized_arrays.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/zero_sized_arrays.cc new file mode 100644 index 00000000000..95d927514c1 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/zero_sized_arrays.cc @@ -0,0 +1,61 @@ +// 2004-10-20 Benjamin Kosnik +// +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.2.2.4 Zero sized arrays + +#include +#include + +void +test01() +{ + const size_t len = 0; + typedef std::tr1::array array_type; + bool test __attribute__((unused)) = true; + + // 1: ? + array_type a = { }; + + // 2 + array_type b; + + // 3 + // begin() == end() + VERIFY( b.begin() == b.end() ); + + // 4: ? + // begin() == end() == unique value. + { + typedef std::tr1::array array_type1; + typedef std::tr1::array array_type2; + array_type1 one; + array_type2 two; + void* v1 = one.begin(); + void* v2 = two.begin(); + VERIFY( v1 != v2 ); + } +} + +int main() +{ + test01(); + return 0; +} + -- 2.11.0