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

Marshall Clow via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 18 20:30:07 PDT 2019


Author: marshall
Date: Mon Mar 18 20:30:07 2019
New Revision: 356435

URL: http://llvm.org/viewvc/llvm-project?rev=356435&view=rev
Log:
Mark 'front()' and 'back()' as noexcept for array/deque/string/string_view. These are just rebranded 'operator[]', and should be noexcept like it is.

Modified:
    libcxx/trunk/include/array
    libcxx/trunk/include/deque
    libcxx/trunk/include/string
    libcxx/trunk/include/string_view
    libcxx/trunk/test/std/containers/sequences/array/front_back.pass.cpp
    libcxx/trunk/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp
    libcxx/trunk/test/std/strings/string.view/string.view.access/back.pass.cpp
    libcxx/trunk/test/std/strings/string.view/string.view.access/front.pass.cpp
    libcxx/trunk/test/std/strings/string.view/string.view.access/index.pass.cpp

Modified: libcxx/trunk/include/array
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/array?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/include/array (original)
+++ libcxx/trunk/include/array Mon Mar 18 20:30:07 2019
@@ -197,10 +197,10 @@ struct _LIBCPP_TEMPLATE_VIS array
     _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 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0
     }
 
     _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();
     }

Modified: libcxx/trunk/include/deque
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/include/deque (original)
+++ libcxx/trunk/include/deque Mon Mar 18 20:30:07 2019
@@ -1338,13 +1338,13 @@ public:
     _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 @@ deque<_Tp, _Allocator>::at(size_type __i
 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 @@ deque<_Tp, _Allocator>::front()
 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 @@ deque<_Tp, _Allocator>::front() const
 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 @@ deque<_Tp, _Allocator>::back()
 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);

Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Mon Mar 18 20:30:07 2019
@@ -1060,10 +1060,10 @@ public:
     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 @@ basic_string<_CharT, _Traits, _Allocator
 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 @@ basic_string<_CharT, _Traits, _Allocator
 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 @@ basic_string<_CharT, _Traits, _Allocator
 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 @@ basic_string<_CharT, _Traits, _Allocator
 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);

Modified: libcxx/trunk/include/string_view
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string_view?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/include/string_view (original)
+++ libcxx/trunk/include/string_view Mon Mar 18 20:30:07 2019
@@ -288,13 +288,13 @@ public:
     }
 
     _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];
     }

Modified: libcxx/trunk/test/std/containers/sequences/array/front_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/array/front_back.pass.cpp?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/array/front_back.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/array/front_back.pass.cpp Mon Mar 18 20:30:07 2019
@@ -68,10 +68,14 @@ int main(int, char**)
       typedef std::array<T, 0> C;
       C c = {};
       C const& cc = c;
-      static_assert((std::is_same<decltype(c.front()), T &>::value), "");
-      static_assert((std::is_same<decltype(cc.front()), const T &>::value), "");
-      static_assert((std::is_same<decltype(c.back()), T &>::value), "");
-      static_assert((std::is_same<decltype(cc.back()), const T &>::value), "");
+      ASSERT_SAME_TYPE(decltype( c.back()), typename C::reference);
+      ASSERT_SAME_TYPE(decltype(cc.back()), typename C::const_reference);
+      LIBCPP_ASSERT_NOEXCEPT(    c.back());
+      LIBCPP_ASSERT_NOEXCEPT(   cc.back());
+      ASSERT_SAME_TYPE(decltype( c.front()), typename C::reference);
+      ASSERT_SAME_TYPE(decltype(cc.front()), typename C::const_reference);
+      LIBCPP_ASSERT_NOEXCEPT(    c.front());
+      LIBCPP_ASSERT_NOEXCEPT(   cc.front());
       if (c.size() > (0)) { // always false
         TEST_IGNORE_NODISCARD c.front();
         TEST_IGNORE_NODISCARD c.back();
@@ -84,10 +88,14 @@ int main(int, char**)
       typedef std::array<const T, 0> C;
       C c = {{}};
       C const& cc = c;
-      static_assert((std::is_same<decltype(c.front()),  const T &>::value), "");
-      static_assert((std::is_same<decltype(cc.front()), const T &>::value), "");
-      static_assert((std::is_same<decltype(c.back()),   const T &>::value), "");
-      static_assert((std::is_same<decltype(cc.back()),  const T &>::value), "");
+      ASSERT_SAME_TYPE(decltype( c.back()), typename C::reference);
+      ASSERT_SAME_TYPE(decltype(cc.back()), typename C::const_reference);
+      LIBCPP_ASSERT_NOEXCEPT(    c.back());
+      LIBCPP_ASSERT_NOEXCEPT(   cc.back());
+      ASSERT_SAME_TYPE(decltype( c.front()), typename C::reference);
+      ASSERT_SAME_TYPE(decltype(cc.front()), typename C::const_reference);
+      LIBCPP_ASSERT_NOEXCEPT(    c.front());
+      LIBCPP_ASSERT_NOEXCEPT(   cc.front());
       if (c.size() > (0)) {
         TEST_IGNORE_NODISCARD c.front();
         TEST_IGNORE_NODISCARD c.back();

Modified: libcxx/trunk/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp Mon Mar 18 20:30:07 2019
@@ -54,8 +54,12 @@ int main(int, char**)
     {
         typedef std::deque<int> C;
         C c = make<std::deque<int> >(10);
-        LIBCPP_ASSERT_NOEXCEPT(c[0]);
-        ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
+        ASSERT_SAME_TYPE(decltype(c[0]), C::reference);
+        LIBCPP_ASSERT_NOEXCEPT(   c[0]);
+        LIBCPP_ASSERT_NOEXCEPT(   c.front());
+        ASSERT_SAME_TYPE(decltype(c.front()), C::reference);
+        LIBCPP_ASSERT_NOEXCEPT(   c.back());
+        ASSERT_SAME_TYPE(decltype(c.back()), C::reference);
         for (int i = 0; i < 10; ++i)
             assert(c[i] == i);
         for (int i = 0; i < 10; ++i)
@@ -66,8 +70,12 @@ int main(int, char**)
     {
         typedef std::deque<int> C;
         const C c = make<std::deque<int> >(10);
-        LIBCPP_ASSERT_NOEXCEPT(c[0]);
-        ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
+        ASSERT_SAME_TYPE(decltype(c[0]), C::const_reference);
+        LIBCPP_ASSERT_NOEXCEPT(   c[0]);
+        LIBCPP_ASSERT_NOEXCEPT(   c.front());
+        ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference);
+        LIBCPP_ASSERT_NOEXCEPT(   c.back());
+        ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference);
         for (int i = 0; i < 10; ++i)
             assert(c[i] == i);
         for (int i = 0; i < 10; ++i)
@@ -79,8 +87,12 @@ int main(int, char**)
     {
         typedef std::deque<int, min_allocator<int>> C;
         C c = make<std::deque<int, min_allocator<int>> >(10);
-        LIBCPP_ASSERT_NOEXCEPT(c[0]);
-        ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
+        ASSERT_SAME_TYPE(decltype(c[0]), C::reference);
+        LIBCPP_ASSERT_NOEXCEPT(   c[0]);
+        LIBCPP_ASSERT_NOEXCEPT(   c.front());
+        ASSERT_SAME_TYPE(decltype(c.front()), C::reference);
+        LIBCPP_ASSERT_NOEXCEPT(   c.back());
+        ASSERT_SAME_TYPE(decltype(c.back()), C::reference);
         for (int i = 0; i < 10; ++i)
             assert(c[i] == i);
         for (int i = 0; i < 10; ++i)
@@ -91,8 +103,12 @@ int main(int, char**)
     {
         typedef std::deque<int, min_allocator<int>> C;
         const C c = make<std::deque<int, min_allocator<int>> >(10);
-        LIBCPP_ASSERT_NOEXCEPT(c[0]);
-        ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
+        ASSERT_SAME_TYPE(decltype(c[0]), C::const_reference);
+        LIBCPP_ASSERT_NOEXCEPT(   c[0]);
+        LIBCPP_ASSERT_NOEXCEPT(   c.front());
+        ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference);
+        LIBCPP_ASSERT_NOEXCEPT(   c.back());
+        ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference);
         for (int i = 0; i < 10; ++i)
             assert(c[i] == i);
         for (int i = 0; i < 10; ++i)

Modified: libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp Mon Mar 18 20:30:07 2019
@@ -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');

Modified: libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp Mon Mar 18 20:30:07 2019
@@ -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');

Modified: libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp Mon Mar 18 20:30:07 2019
@@ -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));

Modified: libcxx/trunk/test/std/strings/string.view/string.view.access/back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.access/back.pass.cpp?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/string.view/string.view.access/back.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/string.view/string.view.access/back.pass.cpp Mon Mar 18 20:30:07 2019
@@ -18,7 +18,10 @@
 
 template <typename CharT>
 bool test ( const CharT *s, size_t len ) {
-    std::basic_string_view<CharT> sv ( s, len );
+    typedef std::basic_string_view<CharT> SV;
+    SV sv ( s, len );
+    ASSERT_SAME_TYPE(decltype(sv.back()), typename SV::const_reference);
+    LIBCPP_ASSERT_NOEXCEPT(   sv.back());
     assert ( sv.length() == len );
     assert ( sv.back() == s[len-1] );
     return &sv.back() == s + len - 1;

Modified: libcxx/trunk/test/std/strings/string.view/string.view.access/front.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.access/front.pass.cpp?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/string.view/string.view.access/front.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/string.view/string.view.access/front.pass.cpp Mon Mar 18 20:30:07 2019
@@ -18,7 +18,10 @@
 
 template <typename CharT>
 bool test ( const CharT *s, size_t len ) {
-    std::basic_string_view<CharT> sv ( s, len );
+    typedef std::basic_string_view<CharT> SV;
+    SV sv ( s, len );
+    ASSERT_SAME_TYPE(decltype(sv.front()), typename SV::const_reference);
+    LIBCPP_ASSERT_NOEXCEPT(   sv.front());
     assert ( sv.length() == len );
     assert ( sv.front() == s[0] );
     return &sv.front() == s;

Modified: libcxx/trunk/test/std/strings/string.view/string.view.access/index.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.access/index.pass.cpp?rev=356435&r1=356434&r2=356435&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/string.view/string.view.access/index.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/string.view/string.view.access/index.pass.cpp Mon Mar 18 20:30:07 2019
@@ -18,7 +18,10 @@
 
 template <typename CharT>
 void test ( const CharT *s, size_t len ) {
-    std::basic_string_view<CharT> sv ( s, len );
+    typedef std::basic_string_view<CharT> SV;
+    SV sv ( s, len );
+    ASSERT_SAME_TYPE(decltype(sv[0]), typename SV::const_reference);
+    LIBCPP_ASSERT_NOEXCEPT(   sv[0]);
     assert ( sv.length() == len );
     for ( size_t i = 0; i < len; ++i ) {
         assert ( sv[i] == s[i] );




More information about the libcxx-commits mailing list