From 9771644a91afe5c53b0433eaedb1d9976f77d856 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 23 Apr 2012 12:26:43 +0000 Subject: re PR libstdc++/53080 (tuple interface to std::array doesn't check bounds) 2012-04-23 Paolo Carlini 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 --- libstdc++-v3/include/std/array | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'libstdc++-v3/include') 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 @@ // -*- 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 - 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 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 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 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 -- cgit v1.2.1