[v3] libstdc++/51850
Paolo Carlini
paolo.carlini@oracle.com
Tue Nov 6 18:20:00 GMT 2012
Hi,
this is what I'm finishing testing to add a debug-mode std::array.
Things work pretty well, but I'm not fiddling for now with the
iterators: std::array must remain an aggregate, thus we can't have base
classes, thus we can't really use the standard debug-mode infrastructure
for those. Basing on the various email exchanges over the last years, I
understand people will like anyway having operator[], and also front and
back checked (consistently with, eg, std::vector). In any case the rest
in enhancement beyond the PR.
Thanks,
Paolo.
////////////////////////
-------------- next part --------------
2012-11-06 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/51850
* include/debug/array: New, debug-mode implementation.
* include/profile/array: New.
* include/std/array: Adjust.
* include/std/tuple: Just include <array>.
* include/Makefile.am: Add.
* include/Makefile.in: Regenerate.
* testsuite/23_containers/array/debug/front1_neg.cc: New.
* testsuite/23_containers/array/debug/
square_brackets_operator1_neg.cc: Likewise.
* testsuite/23_containers/array/debug/front2_neg.cc: Likewise.
* testsuite/23_containers/array/debug/
square_brackets_operator2_neg.cc: Likewise.
* testsuite/23_containers/array/debug/back1_neg.cc: Likewise.
* testsuite/23_containers/array/debug/back2_neg.cc: Likewise.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Tweak
to run only in normal-mode.
* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
Likewise.
* testsuite/23_containers/array/tuple_interface/get_debug_neg.cc: New.
* testsuite/23_containers/array/tuple_interface/
tuple_element_debug_neg.cc: Likewise.
-------------- next part --------------
Index: include/debug/array
===================================================================
--- include/debug/array (revision 0)
+++ include/debug/array (working copy)
@@ -0,0 +1,321 @@
+// Debugging array implementation -*- C++ -*-
+
+// Copyright (C) 2012 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/array
+ * This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_DEBUG_ARRAY
+#define _GLIBCXX_DEBUG_ARRAY 1
+
+#pragma GCC system_header
+
+#include <debug/safe_sequence.h>
+
+#ifndef _GLIBCXX_THROW_OR_ABORT
+# if __EXCEPTIONS
+# define _GLIBCXX_THROW_OR_ABORT(_Exc) (throw (_Exc))
+# else
+# define _GLIBCXX_THROW_OR_ABORT(_Exc) (__builtin_abort())
+# endif
+#endif
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace __debug
+{
+ template<typename _Tp, std::size_t _Nm>
+ struct array
+ {
+ typedef _Tp value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef value_type* iterator;
+ typedef const value_type* const_iterator;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ // Support for zero-sized arrays mandatory.
+ typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
+ typename _AT_Type::_Type _M_elems;
+
+ template<std::size_t _Size>
+ struct _Array_check_subscript
+ {
+ std::size_t size() { return _Size; }
+
+ _Array_check_subscript(std::size_t __index)
+ { __glibcxx_check_subscript(__index); }
+ };
+
+ template<std::size_t _Size>
+ struct _Array_check_nonempty
+ {
+ bool empty() { return _Size == 0; }
+
+ _Array_check_nonempty()
+ { __glibcxx_check_nonempty(); }
+ };
+
+ // No explicit construct/copy/destroy for aggregate type.
+
+ // DR 776.
+ void
+ fill(const value_type& __u)
+ { std::fill_n(begin(), size(), __u); }
+
+ void
+ swap(array& __other)
+ noexcept(noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
+ { std::swap_ranges(begin(), end(), __other.begin()); }
+
+ // Iterators.
+ iterator
+ begin() noexcept
+ { return iterator(data()); }
+
+ const_iterator
+ begin() const noexcept
+ { return const_iterator(data()); }
+
+ iterator
+ end() noexcept
+ { return iterator(data() + _Nm); }
+
+ const_iterator
+ end() const noexcept
+ { return const_iterator(data() + _Nm); }
+
+ reverse_iterator
+ rbegin() noexcept
+ { return reverse_iterator(end()); }
+
+ const_reverse_iterator
+ rbegin() const noexcept
+ { return const_reverse_iterator(end()); }
+
+ reverse_iterator
+ rend() noexcept
+ { return reverse_iterator(begin()); }
+
+ const_reverse_iterator
+ rend() const noexcept
+ { return const_reverse_iterator(begin()); }
+
+ const_iterator
+ cbegin() const noexcept
+ { return const_iterator(data()); }
+
+ const_iterator
+ cend() const noexcept
+ { return const_iterator(data() + _Nm); }
+
+ const_reverse_iterator
+ crbegin() const noexcept
+ { return const_reverse_iterator(end()); }
+
+ const_reverse_iterator
+ crend() const noexcept
+ { return const_reverse_iterator(begin()); }
+
+ // Capacity.
+ constexpr size_type
+ size() const noexcept { return _Nm; }
+
+ constexpr size_type
+ max_size() const noexcept { return _Nm; }
+
+ constexpr bool
+ empty() const noexcept { return size() == 0; }
+
+ // Element access.
+ reference
+ operator[](size_type __n)
+ {
+ __glibcxx_check_subscript(__n);
+ return _AT_Type::_S_ref(_M_elems, __n);
+ }
+
+ constexpr const_reference
+ operator[](size_type __n) const noexcept
+ {
+ return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
+ : (_GLIBCXX_THROW_OR_ABORT (_Array_check_subscript<_Nm>(__n)),
+ _AT_Type::_S_ref(_M_elems, 0));
+ }
+
+ reference
+ at(size_type __n)
+ {
+ if (__n >= _Nm)
+ std::__throw_out_of_range(__N("array::at"));
+ return _AT_Type::_S_ref(_M_elems, __n);
+ }
+
+ constexpr const_reference
+ at(size_type __n) const
+ {
+ // Result of conditional expression must be an lvalue so use
+ // boolean ? lvalue : (throw-expr, lvalue)
+ return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
+ : (std::__throw_out_of_range(__N("array::at")),
+ _AT_Type::_S_ref(_M_elems, 0));
+ }
+
+ reference
+ front()
+ {
+ __glibcxx_check_nonempty();
+ return *begin();
+ }
+
+ constexpr const_reference
+ front() const
+ {
+ return _Nm ? _AT_Type::_S_ref(_M_elems, 0)
+ : (_GLIBCXX_THROW_OR_ABORT (_Array_check_nonempty<_Nm>()),
+ _AT_Type::_S_ref(_M_elems, 0));
+ }
+
+ reference
+ back()
+ {
+ __glibcxx_check_nonempty();
+ return _Nm ? *(end() - 1) : *end();
+ }
+
+ constexpr const_reference
+ back() const
+ {
+ return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
+ : (_GLIBCXX_THROW_OR_ABORT (_Array_check_nonempty<_Nm>()),
+ _AT_Type::_S_ref(_M_elems, 0));
+ }
+
+ pointer
+ data() noexcept
+ { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); }
+
+ const_pointer
+ data() const noexcept
+ { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); }
+ };
+
+ // Array comparisons.
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return std::equal(__one.begin(), __one.end(), __two.begin()); }
+
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return !(__one == __two); }
+
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ 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, std::size_t _Nm>
+ inline bool
+ operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return __two < __one; }
+
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return !(__one > __two); }
+
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return !(__one < __two); }
+
+ // Specialized algorithms.
+ template<typename _Tp, std::size_t _Nm>
+ inline void
+ swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
+ noexcept(noexcept(__one.swap(__two)))
+ { __one.swap(__two); }
+
+ template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+ constexpr _Tp&
+ get(array<_Tp, _Nm>& __arr) noexcept
+ {
+ static_assert(_Int < _Nm, "index is out of bounds");
+ return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
+ _S_ref(__arr._M_elems, _Int);
+ }
+
+ template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+ constexpr _Tp&&
+ get(array<_Tp, _Nm>&& __arr) noexcept
+ {
+ static_assert(_Int < _Nm, "index is out of bounds");
+ return std::move(get<_Int>(__arr));
+ }
+
+ template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+ constexpr const _Tp&
+ get(const array<_Tp, _Nm>& __arr) noexcept
+ {
+ static_assert(_Int < _Nm, "index is out of bounds");
+ return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
+ _S_ref(__arr._M_elems, _Int);
+ }
+} // namespace __debug
+
+ // Tuple interface to class template array.
+
+ /// tuple_size
+ template<typename _Tp>
+ class tuple_size;
+
+ template<typename _Tp, std::size_t _Nm>
+ struct tuple_size<__debug::array<_Tp, _Nm>>
+ : public integral_constant<std::size_t, _Nm> { };
+
+ /// tuple_element
+ template<std::size_t _Int, typename _Tp>
+ class tuple_element;
+
+ template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+ struct tuple_element<_Int, __debug::array<_Tp, _Nm>>
+ {
+ static_assert(_Int < _Nm, "index is out of bounds");
+ typedef _Tp type;
+ };
+} // namespace std
+
+#undef _GLIBCXX_THROW_OR_ABORT
+
+#endif // _GLIBCXX_DEBUG_ARRAY
Index: include/std/tuple
===================================================================
--- include/std/tuple (revision 193210)
+++ include/std/tuple (working copy)
@@ -1,7 +1,6 @@
// <tuple> -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
-// Free Software Foundation, Inc.
+// Copyright (C) 2007-2012 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
@@ -37,6 +36,7 @@
#else
#include <utility>
+#include <array>
#include <bits/uses_allocator.h>
namespace std _GLIBCXX_VISIBILITY(default)
@@ -862,18 +862,6 @@
forward_as_tuple(_Elements&&... __args) noexcept
{ return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
-
- template<typename, std::size_t> struct array;
-
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr _Tp& get(array<_Tp, _Nm>&) noexcept;
-
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr _Tp&& get(array<_Tp, _Nm>&&) noexcept;
-
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr const _Tp& get(const array<_Tp, _Nm>&) noexcept;
-
template<typename>
struct __is_tuple_like_impl : false_type
{ };
Index: include/std/array
===================================================================
--- include/std/array (revision 193210)
+++ include/std/array (working copy)
@@ -41,7 +41,7 @@
namespace std _GLIBCXX_VISIBILITY(default)
{
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
+_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Tp, std::size_t _Nm>
struct __array_traits
@@ -93,8 +93,8 @@
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
// Support for zero-sized arrays mandatory.
- typedef std::__array_traits<_Tp, _Nm> _AT_Type;
- typename _AT_Type::_Type _M_elems;
+ typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
+ typename _AT_Type::_Type _M_elems;
// No explicit construct/copy/destroy for aggregate type.
@@ -210,7 +210,7 @@
back() const
{
return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
- : _AT_Type::_S_ref(_M_elems, _Nm);
+ : _AT_Type::_S_ref(_M_elems, 0);
}
pointer
@@ -289,7 +289,8 @@
get(array<_Tp, _Nm>& __arr) noexcept
{
static_assert(_Int < _Nm, "index is out of bounds");
- return std::__array_traits<_Tp, _Nm>::_S_ref(__arr._M_elems, _Int);
+ return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
+ _S_ref(__arr._M_elems, _Int);
}
template<std::size_t _Int, typename _Tp, std::size_t _Nm>
@@ -305,12 +306,21 @@
get(const array<_Tp, _Nm>& __arr) noexcept
{
static_assert(_Int < _Nm, "index is out of bounds");
- return std::__array_traits<_Tp, _Nm>::_S_ref(__arr._M_elems, _Int);
+ return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
+ _S_ref(__arr._M_elems, _Int);
}
-_GLIBCXX_END_NAMESPACE_VERSION
-} // namespace
+_GLIBCXX_END_NAMESPACE_CONTAINER
+} // namespace std
+#ifdef _GLIBCXX_DEBUG
+# include <debug/array>
+#endif
+
+#ifdef _GLIBCXX_PROFILE
+# include <profile/array>
+#endif
+
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // _GLIBCXX_ARRAY
Index: include/profile/array
===================================================================
--- include/profile/array (revision 0)
+++ include/profile/array (working copy)
@@ -0,0 +1,273 @@
+// Profile array implementation -*- C++ -*-
+
+// Copyright (C) 2012 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file profile/array
+ * This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_PROFILE_ARRAY
+#define _GLIBCXX_PROFILE_ARRAY 1
+
+#pragma GCC system_header
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace __profile
+{
+ template<typename _Tp, std::size_t _Nm>
+ struct array
+ {
+ typedef _Tp value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef value_type* iterator;
+ typedef const value_type* const_iterator;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ // Support for zero-sized arrays mandatory.
+ typedef _GLIBCXX_STD_C::__array_traits<_Tp, _Nm> _AT_Type;
+ typename _AT_Type::_Type _M_elems;
+
+ // No explicit construct/copy/destroy for aggregate type.
+
+ // DR 776.
+ void
+ fill(const value_type& __u)
+ { std::fill_n(begin(), size(), __u); }
+
+ void
+ swap(array& __other)
+ noexcept(noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
+ { std::swap_ranges(begin(), end(), __other.begin()); }
+
+ // Iterators.
+ iterator
+ begin() noexcept
+ { return iterator(data()); }
+
+ const_iterator
+ begin() const noexcept
+ { return const_iterator(data()); }
+
+ iterator
+ end() noexcept
+ { return iterator(data() + _Nm); }
+
+ const_iterator
+ end() const noexcept
+ { return const_iterator(data() + _Nm); }
+
+ reverse_iterator
+ rbegin() noexcept
+ { return reverse_iterator(end()); }
+
+ const_reverse_iterator
+ rbegin() const noexcept
+ { return const_reverse_iterator(end()); }
+
+ reverse_iterator
+ rend() noexcept
+ { return reverse_iterator(begin()); }
+
+ const_reverse_iterator
+ rend() const noexcept
+ { return const_reverse_iterator(begin()); }
+
+ const_iterator
+ cbegin() const noexcept
+ { return const_iterator(data()); }
+
+ const_iterator
+ cend() const noexcept
+ { return const_iterator(data() + _Nm); }
+
+ const_reverse_iterator
+ crbegin() const noexcept
+ { return const_reverse_iterator(end()); }
+
+ const_reverse_iterator
+ crend() const noexcept
+ { return const_reverse_iterator(begin()); }
+
+ // Capacity.
+ constexpr size_type
+ size() const noexcept { return _Nm; }
+
+ constexpr size_type
+ max_size() const noexcept { return _Nm; }
+
+ constexpr bool
+ empty() const noexcept { return size() == 0; }
+
+ // Element access.
+ reference
+ operator[](size_type __n)
+ { return _AT_Type::_S_ref(_M_elems, __n); }
+
+ constexpr const_reference
+ operator[](size_type __n) const noexcept
+ { return _AT_Type::_S_ref(_M_elems, __n); }
+
+ reference
+ at(size_type __n)
+ {
+ if (__n >= _Nm)
+ std::__throw_out_of_range(__N("array::at"));
+ return _AT_Type::_S_ref(_M_elems, __n);
+ }
+
+ constexpr const_reference
+ at(size_type __n) const
+ {
+ // Result of conditional expression must be an lvalue so use
+ // boolean ? lvalue : (throw-expr, lvalue)
+ return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n)
+ : (std::__throw_out_of_range(__N("array::at")),
+ _AT_Type::_S_ref(_M_elems, 0));
+ }
+
+ reference
+ front()
+ { return *begin(); }
+
+ constexpr const_reference
+ front() const
+ { return _AT_Type::_S_ref(_M_elems, 0); }
+
+ reference
+ back()
+ { return _Nm ? *(end() - 1) : *end(); }
+
+ constexpr const_reference
+ back() const
+ {
+ return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
+ : _AT_Type::_S_ref(_M_elems, 0);
+ }
+
+ pointer
+ data() noexcept
+ { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); }
+
+ const_pointer
+ data() const noexcept
+ { return std::__addressof(_AT_Type::_S_ref(_M_elems, 0)); }
+ };
+
+ // Array comparisons.
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return std::equal(__one.begin(), __one.end(), __two.begin()); }
+
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return !(__one == __two); }
+
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ 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, std::size_t _Nm>
+ inline bool
+ operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return __two < __one; }
+
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return !(__one > __two); }
+
+ template<typename _Tp, std::size_t _Nm>
+ inline bool
+ operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
+ { return !(__one < __two); }
+
+ // Specialized algorithms.
+ template<typename _Tp, std::size_t _Nm>
+ inline void
+ swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
+ noexcept(noexcept(__one.swap(__two)))
+ { __one.swap(__two); }
+
+ template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+ constexpr _Tp&
+ get(array<_Tp, _Nm>& __arr) noexcept
+ {
+ static_assert(_Int < _Nm, "index is out of bounds");
+ return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
+ _S_ref(__arr._M_elems, _Int);
+ }
+
+ template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+ constexpr _Tp&&
+ get(array<_Tp, _Nm>&& __arr) noexcept
+ {
+ static_assert(_Int < _Nm, "index is out of bounds");
+ return std::move(get<_Int>(__arr));
+ }
+
+ template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+ constexpr const _Tp&
+ get(const array<_Tp, _Nm>& __arr) noexcept
+ {
+ static_assert(_Int < _Nm, "index is out of bounds");
+ return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
+ _S_ref(__arr._M_elems, _Int);
+ }
+} // namespace __profile
+
+ // Tuple interface to class template array.
+
+ /// tuple_size
+ template<typename _Tp>
+ class tuple_size;
+
+ template<typename _Tp, std::size_t _Nm>
+ struct tuple_size<__profile::array<_Tp, _Nm>>
+ : public integral_constant<std::size_t, _Nm> { };
+
+ /// tuple_element
+ template<std::size_t _Int, typename _Tp>
+ class tuple_element;
+
+ template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+ struct tuple_element<_Int, __profile::array<_Tp, _Nm>>
+ {
+ static_assert(_Int < _Nm, "index is out of bounds");
+ typedef _Tp type;
+ };
+} // namespace std
+
+#endif // _GLIBCXX_PROFILE_ARRAY
Index: include/Makefile.am
===================================================================
--- include/Makefile.am (revision 193210)
+++ include/Makefile.am (working copy)
@@ -705,6 +705,7 @@
debug_srcdir = ${glibcxx_srcdir}/include/debug
debug_builddir = ./debug
debug_headers = \
+ ${debug_srcdir}/array \
${debug_srcdir}/bitset \
${debug_srcdir}/debug.h \
${debug_srcdir}/deque \
@@ -786,6 +787,7 @@
profile_srcdir = ${glibcxx_srcdir}/include/profile
profile_builddir = ./profile
profile_headers = \
+ ${profile_srcdir}/array \
${profile_srcdir}/base.h \
${profile_srcdir}/unordered_map \
${profile_srcdir}/unordered_set \
Index: include/Makefile.in
===================================================================
--- include/Makefile.in (revision 193210)
+++ include/Makefile.in (working copy)
@@ -958,6 +958,7 @@
debug_srcdir = ${glibcxx_srcdir}/include/debug
debug_builddir = ./debug
debug_headers = \
+ ${debug_srcdir}/array \
${debug_srcdir}/bitset \
${debug_srcdir}/debug.h \
${debug_srcdir}/deque \
@@ -1041,6 +1042,7 @@
profile_srcdir = ${glibcxx_srcdir}/include/profile
profile_builddir = ./profile
profile_headers = \
+ ${profile_srcdir}/array \
${profile_srcdir}/base.h \
${profile_srcdir}/unordered_map \
${profile_srcdir}/unordered_set \
Index: testsuite/23_containers/array/tuple_interface/get_neg.cc
===================================================================
--- testsuite/23_containers/array/tuple_interface/get_neg.cc (revision 193210)
+++ testsuite/23_containers/array/tuple_interface/get_neg.cc (working copy)
@@ -1,5 +1,6 @@
+// { dg-do compile }
// { dg-options "-std=gnu++11" }
-// { dg-do compile }
+// { dg-require-normal-mode "" }
// Copyright (C) 2012 Free Software Foundation, Inc.
//
@@ -28,5 +29,5 @@
int n3 = std::get<1>(ca);
// { dg-error "static assertion failed" "" { target *-*-* } 291 }
-// { dg-error "static assertion failed" "" { target *-*-* } 299 }
-// { dg-error "static assertion failed" "" { target *-*-* } 307 }
+// { dg-error "static assertion failed" "" { target *-*-* } 300 }
+// { dg-error "static assertion failed" "" { target *-*-* } 308 }
Index: testsuite/23_containers/array/tuple_interface/get_debug_neg.cc
===================================================================
--- testsuite/23_containers/array/tuple_interface/get_debug_neg.cc (revision 0)
+++ testsuite/23_containers/array/tuple_interface/get_debug_neg.cc (working copy)
@@ -0,0 +1,33 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+// { dg-require-debug-mode "" }
+
+// Copyright (C) 2012 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 <array>
+
+std::array<int, 1> a{};
+const std::array<int, 1> ca{};
+
+int n1 = std::get<1>(a);
+int n2 = std::get<1>(std::move(a));
+int n3 = std::get<1>(ca);
+
+// { dg-error "static assertion failed" "" { target *-*-* } 274 }
+// { dg-error "static assertion failed" "" { target *-*-* } 283 }
+// { dg-error "static assertion failed" "" { target *-*-* } 291 }
Index: testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc
===================================================================
--- testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc (revision 193210)
+++ testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc (working copy)
@@ -1,5 +1,6 @@
+// { dg-do compile }
// { dg-options "-std=gnu++11" }
-// { dg-do compile }
+// { dg-require-normal-mode "" }
// Copyright (C) 2012 Free Software Foundation, Inc.
//
Index: testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc
===================================================================
--- testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc (revision 0)
+++ testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc (working copy)
@@ -0,0 +1,26 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+// { dg-require-debug-mode "" }
+
+// Copyright (C) 2012 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 <array>
+
+typedef std::tuple_element<1, std::array<int, 1>>::type type;
+
+// { dg-error "static assertion failed" "" { target *-*-* } 314 }
Index: testsuite/23_containers/array/debug/front1_neg.cc
===================================================================
--- testsuite/23_containers/array/debug/front1_neg.cc (revision 0)
+++ testsuite/23_containers/array/debug/front1_neg.cc (working copy)
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 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/>.
+//
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++11" }
+// { dg-require-debug-mode "" }
+
+#include <array>
+
+void test01()
+{
+ std::array<int, 0> a;
+ a.front();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc
===================================================================
--- testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc (revision 0)
+++ testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc (working copy)
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 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/>.
+//
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++11" }
+// { dg-require-debug-mode "" }
+
+#include <array>
+
+void test01()
+{
+ std::array<int, 0> a;
+ a[0];
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/23_containers/array/debug/front2_neg.cc
===================================================================
--- testsuite/23_containers/array/debug/front2_neg.cc (revision 0)
+++ testsuite/23_containers/array/debug/front2_neg.cc (working copy)
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 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/>.
+//
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++11" }
+// { dg-require-debug-mode "" }
+
+#include <array>
+
+void test01()
+{
+ constexpr std::array<int, 0> a;
+ a.front();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc
===================================================================
--- testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc (revision 0)
+++ testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc (working copy)
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 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/>.
+//
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++11" }
+// { dg-require-debug-mode "" }
+
+#include <array>
+
+void test01()
+{
+ constexpr std::array<int, 0> a;
+ a[0];
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/23_containers/array/debug/back1_neg.cc
===================================================================
--- testsuite/23_containers/array/debug/back1_neg.cc (revision 0)
+++ testsuite/23_containers/array/debug/back1_neg.cc (working copy)
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 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/>.
+//
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++11" }
+// { dg-require-debug-mode "" }
+
+#include <array>
+
+void test01()
+{
+ std::array<int, 0> a;
+ a.back();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/23_containers/array/debug/back2_neg.cc
===================================================================
--- testsuite/23_containers/array/debug/back2_neg.cc (revision 0)
+++ testsuite/23_containers/array/debug/back2_neg.cc (working copy)
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 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/>.
+//
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++11" }
+// { dg-require-debug-mode "" }
+
+#include <array>
+
+void test01()
+{
+ constexpr std::array<int, 0> a;
+ a.back();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
More information about the Libstdc++
mailing list