diff options
| author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-23 12:26:43 +0000 |
|---|---|---|
| committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-23 12:26:43 +0000 |
| commit | d2ec08dc0179e07f5e9904ce074af11b4f91cb7d (patch) | |
| tree | c583993f5c7e4cd8411fa5936793efa6ca573929 /libstdc++-v3/include/std/array | |
| parent | 8baaba8b466aa1e0bdbe436d3661cbbc9600a910 (diff) | |
| download | ppe42-gcc-d2ec08dc0179e07f5e9904ce074af11b4f91cb7d.tar.gz ppe42-gcc-d2ec08dc0179e07f5e9904ce074af11b4f91cb7d.zip | |
2012-04-23 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/53080
* include/std/array (tuple_element, get): static_assert I < N.
* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
New.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Likewise.
* testsuite/23_containers/array/tuple_interface/tuple_element.cc: Fix.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186702 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/array')
| -rw-r--r-- | libstdc++-v3/include/std/array | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index 3e177444083..e895dd7fc67 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -1,6 +1,7 @@ // <array> -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008, 2009, 2010, 2011, 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 @@ -261,23 +262,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class tuple_element; template<std::size_t _Int, typename _Tp, std::size_t _Nm> - struct tuple_element<_Int, array<_Tp, _Nm> > - { typedef _Tp type; }; + struct tuple_element<_Int, array<_Tp, _Nm>> + { + static_assert(_Int < _Nm, "index is out of bounds"); + typedef _Tp type; + }; template<std::size_t _Int, typename _Tp, std::size_t _Nm> constexpr _Tp& get(array<_Tp, _Nm>& __arr) noexcept - { return __arr._M_instance[_Int]; } + { + static_assert(_Int < _Nm, "index is out of bounds"); + return __arr._M_instance[_Int]; + } template<std::size_t _Int, typename _Tp, std::size_t _Nm> constexpr _Tp&& get(array<_Tp, _Nm>&& __arr) noexcept - { return std::move(get<_Int>(__arr)); } + { + 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 - { return __arr._M_instance[_Int]; } + { + static_assert(_Int < _Nm, "index is out of bounds"); + return __arr._M_instance[_Int]; + } _GLIBCXX_END_NAMESPACE_VERSION } // namespace |

