From 5bcca9ffd167a50dafa2c3958b36e498ee71ad68 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 15 Mar 2019 00:29:35 +0000 Subject: Mark vector::operator[] and front/back as noexcept. We already do this for string and string_view. This should give better codegen inside of noexcept functions. Add tests for op[]/front/back/at, because apparently we had none. llvm-svn: 356224 --- libcxx/include/vector | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'libcxx/include/vector') diff --git a/libcxx/include/vector b/libcxx/include/vector index 79d17675a8c..8413d89bb73 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -664,27 +664,27 @@ public: void reserve(size_type __n); void shrink_to_fit() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n); - _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const; + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT; reference at(size_type __n); const_reference at(size_type __n) const; - _LIBCPP_INLINE_VISIBILITY reference front() + _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); return *this->__begin_; } - _LIBCPP_INLINE_VISIBILITY const_reference front() const + _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); return *this->__begin_; } - _LIBCPP_INLINE_VISIBILITY reference back() + _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); return *(this->__end_ - 1); } - _LIBCPP_INLINE_VISIBILITY const_reference back() const + _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); return *(this->__end_ - 1); @@ -1537,7 +1537,7 @@ vector<_Tp, _Allocator>::end() const _NOEXCEPT template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::reference -vector<_Tp, _Allocator>::operator[](size_type __n) +vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT { _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); return this->__begin_[__n]; @@ -1546,7 +1546,7 @@ vector<_Tp, _Allocator>::operator[](size_type __n) template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::const_reference -vector<_Tp, _Allocator>::operator[](size_type __n) const +vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); return this->__begin_[__n]; -- cgit v1.2.3