diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2012-04-23 12:26:43 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2012-04-23 12:26:43 +0000 |
commit | 9771644a91afe5c53b0433eaedb1d9976f77d856 (patch) | |
tree | c583993f5c7e4cd8411fa5936793efa6ca573929 /libstdc++-v3/include | |
parent | ff5be0e34e72b6f752da6ad73be280a514bc78b0 (diff) | |
download | gcc-9771644a91afe5c53b0433eaedb1d9976f77d856.tar.gz |
re PR libstdc++/53080 (tuple interface to std::array doesn't check bounds)
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.
From-SVN: r186702
Diffstat (limited to 'libstdc++-v3/include')
-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 |