Mark 'front()' and 'back()' as noexcept for array/deque/string/string_view. These are just rebranded 'operator[]', and should be noexcept like it is.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@356435 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2019-03-19 03:30:07 +00:00
parent e7641c9db9
commit ddb1b0576a
12 changed files with 94 additions and 45 deletions

View File

@@ -25,6 +25,10 @@ void
test(S s)
{
const S& cs = s;
ASSERT_SAME_TYPE(decltype( s.back()), typename S::reference);
ASSERT_SAME_TYPE(decltype(cs.back()), typename S::const_reference);
LIBCPP_ASSERT_NOEXCEPT( s.back());
LIBCPP_ASSERT_NOEXCEPT( cs.back());
assert(&cs.back() == &cs[cs.size()-1]);
assert(&s.back() == &s[cs.size()-1]);
s.back() = typename S::value_type('z');

View File

@@ -25,6 +25,10 @@ void
test(S s)
{
const S& cs = s;
ASSERT_SAME_TYPE(decltype( s.front()), typename S::reference);
ASSERT_SAME_TYPE(decltype(cs.front()), typename S::const_reference);
LIBCPP_ASSERT_NOEXCEPT( s.front());
LIBCPP_ASSERT_NOEXCEPT( cs.front());
assert(&cs.front() == &cs[0]);
assert(&s.front() == &s[0]);
s.front() = typename S::value_type('z');

View File

@@ -26,6 +26,10 @@ int main(int, char**)
typedef std::string S;
S s("0123456789");
const S& cs = s;
ASSERT_SAME_TYPE(decltype( s[0]), typename S::reference);
ASSERT_SAME_TYPE(decltype(cs[0]), typename S::const_reference);
LIBCPP_ASSERT_NOEXCEPT( s[0]);
LIBCPP_ASSERT_NOEXCEPT( cs[0]);
for (S::size_type i = 0; i < cs.size(); ++i)
{
assert(s[i] == static_cast<char>('0' + i));
@@ -40,6 +44,10 @@ int main(int, char**)
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
S s("0123456789");
const S& cs = s;
ASSERT_SAME_TYPE(decltype( s[0]), typename S::reference);
ASSERT_SAME_TYPE(decltype(cs[0]), typename S::const_reference);
LIBCPP_ASSERT_NOEXCEPT( s[0]);
LIBCPP_ASSERT_NOEXCEPT( cs[0]);
for (S::size_type i = 0; i < cs.size(); ++i)
{
assert(s[i] == static_cast<char>('0' + i));