* [google][gcc-4.9][committed] Add inexpensive bounds checks to std::array
@ 2015-08-01 20:31 Paul Pluzhnikov
0 siblings, 0 replies; only message in thread
From: Paul Pluzhnikov @ 2015-08-01 20:31 UTC (permalink / raw)
To: Brooks Moses; +Cc: gcc-patches, libstdc++
[-- Attachment #1: Type: text/plain, Size: 297 bytes --]
Greetings,
For google b/9650176, attached patch adds bounds checks to std::array
and updates expected line numbers in tests.
This is similar to the checks that we do for std::vector.
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56109
Committed as r226465.
Thanks,
--
Paul Pluzhnikov
[-- Attachment #2: b9650176.20150801.txt --]
[-- Type: text/plain, Size: 2206 bytes --]
Index: libstdc++-v3/include/std/array
===================================================================
--- libstdc++-v3/include/std/array (revision 226462)
+++ libstdc++-v3/include/std/array (working copy)
@@ -50,7 +50,18 @@
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>
Index: libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc (revision 226462)
+++ libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc (working copy)
@@ -28,6 +28,6 @@
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 }
Index: libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc (revision 226462)
+++ libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc (working copy)
@@ -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 }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-08-01 20:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-01 20:31 [google][gcc-4.9][committed] Add inexpensive bounds checks to std::array Paul Pluzhnikov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).