diff options
author | Paul Pluzhnikov <ppluzhnikov@google.com> | 2015-08-01 20:28:18 +0000 |
---|---|---|
committer | Paul Pluzhnikov <ppluzhnikov@google.com> | 2015-08-01 20:28:18 +0000 |
commit | 67339e91d6ad24c0276e18ac2f7993e5d5dc3252 (patch) | |
tree | 2695716331d3f0c1ba16fb0c26985cfc1cfa8778 | |
parent | 3e6c7e1843e6879320e1b4b0132782023c478084 (diff) |
For google b/9650176, add bounds checks to std::array and update expected line numbers in tests.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/google/gcc-4_9@226465 138bc75d-0d04-0410-961f-82ee72b054a4
3 files changed, 15 insertions, 4 deletions
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index b7abeb09b79..58557901a6b 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -50,7 +50,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER static constexpr _Tp* _S_ptr(const _Type& __t, std::size_t __n) noexcept +#if __google_stl_debug_array + { + return __n < _Nm + ? const_cast<_Tp*>(std::__addressof(__t[__n])) + : (std::__throw_out_of_range_fmt(__N("array::_S_ptr: __n " + "(which is %zu) >= size() " + "(which is %zu)"), + __n, _Nm), nullptr); + } +#else { return const_cast<_Tp*>(std::__addressof(__t[__n])); } +#endif }; template<typename _Tp> diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc index 979d7f6b5aa..64ecfc60480 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc @@ -28,6 +28,6 @@ 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 } +// { dg-error "static assertion failed" "" { target *-*-* } 285 } +// { dg-error "static assertion failed" "" { target *-*-* } 294 } +// { dg-error "static assertion failed" "" { target *-*-* } 302 } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc index f80798c9108..0806ac16a35 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc @@ -23,4 +23,4 @@ typedef std::tuple_element<1, std::array<int, 1>>::type type; -// { dg-error "static assertion failed" "" { target *-*-* } 320 } +// { dg-error "static assertion failed" "" { target *-*-* } 331 } |