]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Enable assertions in constexpr string_view members [PR 71960]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Aug 2020 13:47:51 +0000 (14:47 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 26 Aug 2020 13:50:16 +0000 (14:50 +0100)
Since GCC 6.1 there is no reason we can't just use __glibcxx_assert in
constexpr functions in string_view. As long as the condition is true,
there will be no call to std::__replacement_assert that would make the
function ineligible for constant evaluation.

PR libstdc++/71960
* include/experimental/string_view (basic_string_view):
Enable debug assertions.
* include/std/string_view (basic_string_view):
Likewise.

(cherry picked from commit 3eefb302d2bd8502cb3d8fe44e672b11092ccaf6)

libstdc++-v3/include/experimental/string_view
libstdc++-v3/include/std/string_view

index 9e810dec8445c32c31df23df797594201343090e..78c4d332b2752762e96b6ceff9b00f28f96b337f 100644 (file)
@@ -178,8 +178,7 @@ inline namespace fundamentals_v1
       constexpr const _CharT&
       operator[](size_type __pos) const
       {
-       // TODO: Assert to restore in a way compatible with the constexpr.
-       // __glibcxx_assert(__pos < this->_M_len);
+       __glibcxx_assert(__pos < this->_M_len);
        return *(this->_M_str + __pos);
       }
 
@@ -198,16 +197,14 @@ inline namespace fundamentals_v1
       constexpr const _CharT&
       front() const
       {
-       // TODO: Assert to restore in a way compatible with the constexpr.
-       // __glibcxx_assert(this->_M_len > 0);
+       __glibcxx_assert(this->_M_len > 0);
        return *this->_M_str;
       }
 
       constexpr const _CharT&
       back() const
       {
-       // TODO: Assert to restore in a way compatible with the constexpr.
-       // __glibcxx_assert(this->_M_len > 0);
+       __glibcxx_assert(this->_M_len > 0);
        return *(this->_M_str + this->_M_len - 1);
       }
 
index 4d90438e6be1540cc6f6f1771897ceb4ed28e203..b7a0421950e39b025e359d27467a51a3c4ba174c 100644 (file)
@@ -193,8 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       constexpr const_reference
       operator[](size_type __pos) const noexcept
       {
-       // TODO: Assert to restore in a way compatible with the constexpr.
-       // __glibcxx_assert(__pos < this->_M_len);
+       __glibcxx_assert(__pos < this->_M_len);
        return *(this->_M_str + __pos);
       }
 
@@ -211,16 +210,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       constexpr const_reference
       front() const noexcept
       {
-       // TODO: Assert to restore in a way compatible with the constexpr.
-       // __glibcxx_assert(this->_M_len > 0);
+       __glibcxx_assert(this->_M_len > 0);
        return *this->_M_str;
       }
 
       constexpr const_reference
       back() const noexcept
       {
-       // TODO: Assert to restore in a way compatible with the constexpr.
-       // __glibcxx_assert(this->_M_len > 0);
+       __glibcxx_assert(this->_M_len > 0);
        return *(this->_M_str + this->_M_len - 1);
       }