diff options
19 files changed, 812 insertions, 24 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a9a8d21..ac70fd7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,27 @@ +2004-10-21 Benjamin Kosnik <bkoz@redhat.com> + + * 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 <pcarlini@suse.de> Benjamin Kosnik <bkoz@redhat.com> diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 141138b..9058dd6 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 7f092ad..d355285 100644 --- a/libstdc++-v3/include/tr1/array +++ b/libstdc++-v3/include/tr1/array @@ -32,6 +32,8 @@ #include <new> #include <iterator> +#include <algorithm> +#include <bits/functexcept.h> //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<typename _Tp, size_t _Nm = 1> 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<iterator> reverse_iterator; typedef std::reverse_iterator<const_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<iterator>(&_M_instance[_S_index - 1]); } + { return reinterpret_cast<iterator>(&_M_instance[_Nm]); } const_iterator end() const - { return reinterpret_cast<const_iterator>(&_M_instance[_S_index - 1]); } + { return reinterpret_cast<const_iterator>(&_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<const_reference>(_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<reference>(_M_instance[__n]); } @@ -161,7 +160,7 @@ namespace tr1 template<typename _Tp, size_t _Nm> bool operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + { return std::equal(__one.begin(), __one.end(), __two.begin()); } template<typename _Tp, size_t _Nm> bool @@ -170,23 +169,26 @@ namespace tr1 template<typename _Tp, size_t _Nm> 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<typename _Tp, size_t _Nm> bool operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + { return __two < __one; } template<typename _Tp, size_t _Nm> bool operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + { return !(__one > __two); } template<typename _Tp, size_t _Nm> bool operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return false; } + { return !(__one < __two); } // [6.2.2.2] Specialized algorithms. template<typename _Tp, size_t _Nm> 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 0000000..844ca5a --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/empty.cc @@ -0,0 +1,53 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + { + const size_t len = 5; + typedef std::tr1::array<int, len> 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<int, len> 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 0000000..d081b3d --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/max_size.cc @@ -0,0 +1,53 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + { + const size_t len = 5; + typedef std::tr1::array<int, len> 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<int, len> 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 0000000..d081b3d --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/capacity/size.cc @@ -0,0 +1,53 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + { + const size_t len = 5; + typedef std::tr1::array<int, len> 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<int, len> 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 0000000..0ace9ae --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/equal.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..3badc20 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/greater.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..aaf0cb0 --- /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 <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..c0debec --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/less.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..11ae4e8 --- /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 <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..f166ae7 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/comparison_operators/not_equal.cc @@ -0,0 +1,45 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..f885424 --- /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 <bkoz@redhat.com> +// +// 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 <tr1/array> + +void +test01() +{ + typedef std::tr1::array<int, 5> 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 0000000..1b17856 --- /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 <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <stdexcept> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..890704f --- /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 <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..2643600 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/contiguous.cc @@ -0,0 +1,46 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 5; + typedef std::tr1::array<int, len> 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 0000000..f4d7b68 --- /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 <bkoz@redhat.com> +// +// 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 <tr1/array> + +template class std::tr1::array<int, 5>; 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 0000000..225426d --- /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 <bkoz@redhat.com> +// +// 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 <tr1/array> + +void test01() +{ + // Check for required typedefs + typedef std::tr1::array<int, 5> 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 0000000..95d9275 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/zero_sized_arrays.cc @@ -0,0 +1,61 @@ +// 2004-10-20 Benjamin Kosnik <bkoz@redhat.com> +// +// 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 <tr1/array> +#include <testsuite_hooks.h> + +void +test01() +{ + const size_t len = 0; + typedef std::tr1::array<int, len> 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<long, len> array_type1; + typedef std::tr1::array<char, len> array_type2; + array_type1 one; + array_type2 two; + void* v1 = one.begin(); + void* v2 = two.begin(); + VERIFY( v1 != v2 ); + } +} + +int main() +{ + test01(); + return 0; +} + |