[committed] libstdc++: Fix noexcept-specifier for ranges::empty

Message ID YMfUuKZ+z+E6RH/3@redhat.com
State New
Headers show
Series
  • [committed] libstdc++: Fix noexcept-specifier for ranges::empty
Related show

Commit Message

Michael Meissner via Gcc-patches June 14, 2021, 10:14 p.m.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>


libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (ranges::empty): Check whether
	conversion to bool can throw.
	* testsuite/std/ranges/access/empty.cc: Check for correct
	noexcept-specifier.

Tested powerpc64le-linux. Committed to trunk.
commit f9598d89a9f5a327ecdfa6f6978a0cfbe4447111
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jun 14 22:42:05 2021

    libstdc++: Fix noexcept-specifier for ranges::empty
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

    
    libstdc++-v3/ChangeLog:
    
            * include/bits/ranges_base.h (ranges::empty): Check whether
            conversion to bool can throw.
            * testsuite/std/ranges/access/empty.cc: Check for correct
            noexcept-specifier.

Patch

diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h
index 728d3ad2b25..3bc657ca17e 100644
--- a/libstdc++-v3/include/bits/ranges_base.h
+++ b/libstdc++-v3/include/bits/ranges_base.h
@@ -476,7 +476,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 9044dd155da..b2d8b105325 100644
--- a/libstdc++-v3/testsuite/std/ranges/access/empty.cc
+++ b/libstdc++-v3/testsuite/std/ranges/access/empty.cc
@@ -89,10 +89,41 @@  test03()
   static_assert( std::ranges::empty(R2{}) );
 }
 
+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();
   test03();
+  test04();
 }