http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53080
Bug #: 53080 Summary: std::array - std::get() and std::tuple_element is nothing bounds check Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: faithandbr...@gmail.com "23.3.2.9 Tuple interface to class template array" in N3337(C++ Specification Draft) tuple_element<I, array<T, N> >::type Requires: I < N. The program is ill-formed if I is out of bounds. template <size_t I, class T, size_t N> T& get(array<T, N>& a) noexcept; Requires: I < N. The program is ill-formed if I is out of bounds. GCC 4.7.0 libstdc++ <array> header is no check bounds. I think need static_assert to tuple_element and get(). Issue code is follow: template<std::size_t _Int, typename _Tp, std::size_t _Nm> struct tuple_element<_Int, array<_Tp, _Nm> > { 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]; } 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)); } 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]; }