From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id A36B0386EC42; Tue, 1 Sep 2020 10:00:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A36B0386EC42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598954418; bh=q0XXx+WBpgfvJ86x36kC7unYxOvCLAYZqroGmy2TSLI=; h=From:To:Subject:Date:From; b=aCQ8fMqHCZyadIby50Aeb8+fy2JY4PRGwtpSVvreSR73T2ehUGkc+ZyaksL2dNgDr ILv+fnGrku6MrnVgfUM+o48ARIORD3HAcBkUGk3FTxuT+WNfkTBcyKE4iN13ouKtv2 mkroL8RmbT+GKRi7X7nQ48gllLMSWA6a/xqy8k9I= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-10] libstdc++: Enable assertions in constexpr string_view members [PR 71960] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/devel/omp/gcc-10 X-Git-Oldrev: 4b6366f24890e25a07f9a045d15633c5b1fb80cb X-Git-Newrev: 85847fd421d7760f45f0e69c7ae3607f2f898bb8 Message-Id: <20200901100018.A36B0386EC42@sourceware.org> Date: Tue, 1 Sep 2020 10:00:18 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Sep 2020 10:00:18 -0000 https://gcc.gnu.org/g:85847fd421d7760f45f0e69c7ae3607f2f898bb8 commit 85847fd421d7760f45f0e69c7ae3607f2f898bb8 Author: Jonathan Wakely Date: Wed Aug 26 14:47:51 2020 +0100 libstdc++: Enable assertions in constexpr string_view members [PR 71960] 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) 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 629db577c29..5567184cf0e 100644 --- a/libstdc++-v3/include/experimental/string_view +++ b/libstdc++-v3/include/experimental/string_view @@ -179,8 +179,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); } @@ -199,16 +198,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 7c7c1b3b5dd..afb8dcbce82 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -207,8 +207,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); } @@ -225,16 +224,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); }