aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/array
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely.gcc@gmail.com>2012-09-09 17:56:51 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2012-09-09 18:56:51 +0100
commit885e812159dcbf83f790eee9d839f91daa553eb3 (patch)
tree9a602af81e687d5ca4c3dd7a733930b7460808f1 /libstdc++-v3/include/std/array
parentb4661bfe214bf5ae119c511f994336ccc3fe144c (diff)
downloadgcc-885e812159dcbf83f790eee9d839f91daa553eb3.zip
gcc-885e812159dcbf83f790eee9d839f91daa553eb3.tar.gz
gcc-885e812159dcbf83f790eee9d839f91daa553eb3.tar.bz2
re PR libstdc++/54388 (std::array.at() const results in undefined behaviour)
PR libstdc++/54388 * include/std/array (array::at() const): Ensure lvalue result. * testsuite/23_containers/array/element_access/54388.cc: New. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers. * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: Likewise. From-SVN: r191114
Diffstat (limited to 'libstdc++-v3/include/std/array')
-rw-r--r--libstdc++-v3/include/std/array16
1 files changed, 4 insertions, 12 deletions
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 58263ce..4ee2199 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -164,22 +164,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _M_instance[__n];
}
-#ifdef __EXCEPTIONS
constexpr const_reference
at(size_type __n) const
{
- return __n < _Nm ?
- _M_instance[__n] : throw out_of_range(__N("array::at"));
+ // Result of conditional expression must be an lvalue so use
+ // boolean ? lvalue : (throw-expr, lvalue)
+ return __n < _Nm ? _M_instance[__n]
+ : (std::__throw_out_of_range(__N("array::at")), _M_instance[0]);
}
-#else
- const_reference
- at(size_type __n) const
- {
- if (__n >= _Nm)
- std::__throw_out_of_range(__N("array::at"));
- return _M_instance[__n];
- }
-#endif
reference
front()