Mark 'front()' and 'back()' as noexcept for array/deque/string/string_view. These are just rebranded 'operator[]', and should be noexcept like it is.
llvm-svn: 356435
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 9ea0e473f0b96455b918eefcf8fc535638674a1f
diff --git a/include/array b/include/array
index 320bfd5..418a2a9 100644
--- a/include/array
+++ b/include/array
@@ -197,10 +197,10 @@
_LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
_LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size - 1];}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size - 1];}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return __elems_[0];}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return __elems_[_Size - 1];}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return __elems_[_Size - 1];}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
value_type* data() _NOEXCEPT {return __elems_;}
@@ -327,25 +327,25 @@
}
_LIBCPP_INLINE_VISIBILITY
- reference front() {
+ reference front() _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
- const_reference front() const {
+ const_reference front() const _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
- reference back() {
+ reference back() _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
- const_reference back() const {
+ const_reference back() const _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
diff --git a/include/deque b/include/deque
index 9b612e1..d3ccf2e 100644
--- a/include/deque
+++ b/include/deque
@@ -1338,13 +1338,13 @@
_LIBCPP_INLINE_VISIBILITY
const_reference at(size_type __i) const;
_LIBCPP_INLINE_VISIBILITY
- reference front();
+ reference front() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
- const_reference front() const;
+ const_reference front() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
- reference back();
+ reference back() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
- const_reference back() const;
+ const_reference back() const _NOEXCEPT;
// 23.2.2.3 modifiers:
void push_front(const value_type& __v);
@@ -1785,7 +1785,7 @@
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::reference
-deque<_Tp, _Allocator>::front()
+deque<_Tp, _Allocator>::front() _NOEXCEPT
{
return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
+ __base::__start_ % __base::__block_size);
@@ -1794,7 +1794,7 @@
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::const_reference
-deque<_Tp, _Allocator>::front() const
+deque<_Tp, _Allocator>::front() const _NOEXCEPT
{
return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
+ __base::__start_ % __base::__block_size);
@@ -1803,7 +1803,7 @@
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::reference
-deque<_Tp, _Allocator>::back()
+deque<_Tp, _Allocator>::back() _NOEXCEPT
{
size_type __p = __base::size() + __base::__start_ - 1;
return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
@@ -1812,7 +1812,7 @@
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::const_reference
-deque<_Tp, _Allocator>::back() const
+deque<_Tp, _Allocator>::back() const _NOEXCEPT
{
size_type __p = __base::size() + __base::__start_ - 1;
return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
diff --git a/include/string b/include/string
index ab6052d..3b01c41 100644
--- a/include/string
+++ b/include/string
@@ -1060,10 +1060,10 @@
void push_back(value_type __c);
_LIBCPP_INLINE_VISIBILITY
void pop_back();
- _LIBCPP_INLINE_VISIBILITY reference front();
- _LIBCPP_INLINE_VISIBILITY const_reference front() const;
- _LIBCPP_INLINE_VISIBILITY reference back();
- _LIBCPP_INLINE_VISIBILITY const_reference back() const;
+ _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT;
+ _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
+ _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT;
+ _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
@@ -3237,7 +3237,7 @@
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::reference
-basic_string<_CharT, _Traits, _Allocator>::front()
+basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
return *__get_pointer();
@@ -3246,7 +3246,7 @@
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::const_reference
-basic_string<_CharT, _Traits, _Allocator>::front() const
+basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
return *data();
@@ -3255,7 +3255,7 @@
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::reference
-basic_string<_CharT, _Traits, _Allocator>::back()
+basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
return *(__get_pointer() + size() - 1);
@@ -3264,7 +3264,7 @@
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::const_reference
-basic_string<_CharT, _Traits, _Allocator>::back() const
+basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
return *(data() + size() - 1);
diff --git a/include/string_view b/include/string_view
index 79565c2..9a6eb0c 100644
--- a/include/string_view
+++ b/include/string_view
@@ -288,13 +288,13 @@
}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
- const_reference front() const
+ const_reference front() const _NOEXCEPT
{
return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
- const_reference back() const
+ const_reference back() const _NOEXCEPT
{
return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
}