public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r10-10577] libstdc++: Fix noexcept-specifier for ranges::empty
Date: Tue, 26 Apr 2022 13:13:17 +0000 (GMT)	[thread overview]
Message-ID: <20220426131317.32023385840C@sourceware.org> (raw)

https://gcc.gnu.org/g:01c72ccad94e4f7b71504e502cba43d62b658143

commit r10-10577-g01c72ccad94e4f7b71504e502cba43d62b658143
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jun 14 22:42:05 2021 +0100

    libstdc++: Fix noexcept-specifier for ranges::empty
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/range_access.h (ranges::empty): Check whether
            conversion to bool can throw.
            * testsuite/std/ranges/access/empty.cc: Check for correct
            noexcept-specifier.
    
    (cherry picked from commit f9598d89a9f5a327ecdfa6f6978a0cfbe4447111)

Diff:
---
 libstdc++-v3/include/bits/range_access.h          |  2 +-
 libstdc++-v3/testsuite/std/ranges/access/empty.cc | 31 +++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h
index 36bc55e6559..aee72c3fae4 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -773,7 +773,7 @@ namespace ranges
 	_S_noexcept()
 	{
 	  if constexpr (__member_empty<_Tp>)
-	    return noexcept(std::declval<_Tp>().empty());
+	    return noexcept(bool(std::declval<_Tp>().empty()));
 	  else if constexpr (__size0_empty<_Tp>)
 	    return noexcept(_Size{}(std::declval<_Tp>()) == 0);
 	  else
diff --git a/libstdc++-v3/testsuite/std/ranges/access/empty.cc b/libstdc++-v3/testsuite/std/ranges/access/empty.cc
index 4b54ed7b367..47dfca6513f 100644
--- a/libstdc++-v3/testsuite/std/ranges/access/empty.cc
+++ b/libstdc++-v3/testsuite/std/ranges/access/empty.cc
@@ -68,9 +68,40 @@ test02()
   VERIFY( !std::ranges::empty(so) );
 }
 
+void
+test04()
+{
+  struct E1
+  {
+    bool empty() const noexcept { return {}; }
+  };
+
+  static_assert( noexcept(std::ranges::empty(E1{})) );
+
+  struct E2
+  {
+    bool empty() const noexcept(false) { return {}; }
+  };
+
+  static_assert( ! noexcept(std::ranges::empty(E2{})) );
+
+  struct E3
+  {
+    struct B
+    {
+      explicit operator bool() const noexcept(false) { return true; }
+    };
+
+    B empty() const noexcept { return {}; }
+  };
+
+  static_assert( ! noexcept(std::ranges::empty(E3{})) );
+}
+
 int
 main()
 {
   test01();
   test02();
+  test04();
 }


                 reply	other threads:[~2022-04-26 13:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220426131317.32023385840C@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).