[gcc(refs/vendors/redhat/heads/gcc-8-branch)] libstdc++: Enable assertions in constexpr string_view members [PR 71960]

Jakub Jelinek jakub@gcc.gnu.org
Thu Sep 17 17:18:20 GMT 2020


https://gcc.gnu.org/g:050ccc3b983ef6716e4cc0f6a4db21e502279093

commit 050ccc3b983ef6716e4cc0f6a4db21e502279093
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 10 15:49:26 2020 +0100

    libstdc++: Enable assertions in constexpr string_view members [PR 71960]
    
    There is no longer any reason we can't just use __glibcxx_assert in
    constexpr functions. 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.

Diff:
---
 libstdc++-v3/include/experimental/string_view | 9 +++------
 libstdc++-v3/include/std/string_view          | 9 +++------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/experimental/string_view b/libstdc++-v3/include/experimental/string_view
index 2bbd9aa8a0a..107d801d8ee 100644
--- a/libstdc++-v3/include/experimental/string_view
+++ b/libstdc++-v3/include/experimental/string_view
@@ -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);
       }
 
diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view
index 96962e39bf4..412cc17de24 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -169,8 +169,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       constexpr const _CharT&
       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);
       }
 
@@ -187,16 +186,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       constexpr const _CharT&
       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 _CharT&
       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);
       }


More information about the Gcc-cvs mailing list