]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add conditional noexcept to remaining range access functions
authorJonathan Wakely <jwakely@redhat.com>
Wed, 12 Feb 2025 19:43:05 +0000 (19:43 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Sat, 15 Feb 2025 10:58:56 +0000 (10:58 +0000)
Add conditional noexcept to the remaining range access functions that
were not changed in r15-5669-g8692cb10e82e72. This is now being proposed
for C++26 by P3623R0 (not published yet).

libstdc++-v3/ChangeLog:

* include/bits/range_access.h (rbegin, rend, crbegin, crend):
Add conditional noexcept, as per P3623R0.
* testsuite/24_iterators/headers/iterator/range_access.cc: Add
noexcept-specifier to rbegin, rend, crbegin and crend
declarations.

libstdc++-v3/include/bits/range_access.h
libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc

index 9295c0fa2adeb2ea85773084fafa0e84c52b548f..e0afee41f090b7d07ab6991cacd592cd938617d1 100644 (file)
@@ -153,7 +153,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Container>
     [[__nodiscard__, __gnu__::__always_inline__]]
     inline _GLIBCXX17_CONSTEXPR auto
-    rbegin(_Container& __cont) -> decltype(__cont.rbegin())
+    rbegin(_Container& __cont) noexcept(noexcept(__cont.rbegin()))
+      -> decltype(__cont.rbegin())
     { return __cont.rbegin(); }
 
   /**
@@ -164,7 +165,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Container>
     [[__nodiscard__, __gnu__::__always_inline__]]
     inline _GLIBCXX17_CONSTEXPR auto
-    rbegin(const _Container& __cont) -> decltype(__cont.rbegin())
+    rbegin(const _Container& __cont) noexcept(noexcept(__cont.rbegin()))
+      -> decltype(__cont.rbegin())
     { return __cont.rbegin(); }
 
   /**
@@ -175,7 +177,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Container>
     [[__nodiscard__, __gnu__::__always_inline__]]
     inline _GLIBCXX17_CONSTEXPR auto
-    rend(_Container& __cont) -> decltype(__cont.rend())
+    rend(_Container& __cont) noexcept(noexcept(__cont.rend()))
+      -> decltype(__cont.rend())
     { return __cont.rend(); }
 
   /**
@@ -186,7 +189,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Container>
     [[__nodiscard__, __gnu__::__always_inline__]]
     inline _GLIBCXX17_CONSTEXPR auto
-    rend(const _Container& __cont) -> decltype(__cont.rend())
+    rend(const _Container& __cont) noexcept(noexcept(__cont.rend()))
+      -> decltype(__cont.rend())
     { return __cont.rend(); }
 
   /**
@@ -241,7 +245,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Container>
     [[__nodiscard__, __gnu__::__always_inline__]]
     inline _GLIBCXX17_CONSTEXPR auto
-    crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont))
+    crbegin(const _Container& __cont) noexcept(noexcept(std::rbegin(__cont)))
+      -> decltype(std::rbegin(__cont))
     { return std::rbegin(__cont); }
 
   /**
@@ -252,7 +257,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Container>
     [[__nodiscard__, __gnu__::__always_inline__]]
     inline _GLIBCXX17_CONSTEXPR auto
-    crend(const _Container& __cont) -> decltype(std::rend(__cont))
+    crend(const _Container& __cont) noexcept(noexcept(std::rend(__cont)))
+      -> decltype(std::rend(__cont))
     { return std::rend(__cont); }
 
 #endif // C++14
index 23676ad1d7a3bff24f6f9ae941f23933c6760a85..982cb16f79baa85c60b13aac45066fc42a718d2e 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifdef _GLIBCXX_RELEASE
 // Conditional noexcept on these functions is a libstdc++ extension
-# define NOTHROW(F) noexcept(noexcept(c.F()))
+# define NOTHROW(F) noexcept(noexcept(F))
 #else
 # define NOTHROW(F)
 #endif
@@ -42,17 +42,17 @@ namespace std
 {
   template<class C>
     CONSTEXPR_17 auto
-    begin(C& c) NOTHROW(begin) -> decltype(c.begin());
+    begin(C& c) NOTHROW(c.begin()) -> decltype(c.begin());
   template<class C>
     CONSTEXPR_17 auto
-    begin(const C& c) NOTHROW(begin) -> decltype(c.begin());
+    begin(const C& c) NOTHROW(c.begin()) -> decltype(c.begin());
 
   template<class C>
     CONSTEXPR_17 auto
-    end(C& c) NOTHROW(end) -> decltype(c.end());
+    end(C& c) NOTHROW(c.end()) -> decltype(c.end());
   template<class C>
     CONSTEXPR_17 auto
-    end(const C& c) NOTHROW(end) -> decltype(c.end());
+    end(const C& c) NOTHROW(c.end()) -> decltype(c.end());
 
   template<class T, size_t N>
     CONSTEXPR_14 T*
@@ -71,17 +71,17 @@ namespace std
 
   template<class C>
     CONSTEXPR_17 auto
-    rbegin(C& c) -> decltype(c.rbegin());
+    rbegin(C& c) NOTHROW(c.rbegin()) -> decltype(c.rbegin());
   template<class C>
     CONSTEXPR_17 auto
-    rbegin(const C& c) -> decltype(c.rbegin());
+    rbegin(const C& c) NOTHROW(c.rbegin()) -> decltype(c.rbegin());
 
   template<class C>
     CONSTEXPR_17 auto
-    rend(C& c) -> decltype(c.rend());
+    rend(C& c) NOTHROW(c.rend()) -> decltype(c.rend());
   template<class C>
     CONSTEXPR_17 auto
-    rend(const C& c) -> decltype(c.rend());
+    rend(const C& c) NOTHROW(c.rend()) -> decltype(c.rend());
 
   template<class T, size_t N>
     CONSTEXPR_17 reverse_iterator<T*>
@@ -99,9 +99,9 @@ namespace std
 
   template<class C>
     CONSTEXPR_17 auto
-    crbegin(const C& c) -> decltype(std::rbegin(c));
+    crbegin(const C& c) NOTHROW(std::rbegin(c)) -> decltype(std::rbegin(c));
   template<class C>
     CONSTEXPR_17 auto
-    cend(const C& c) -> decltype(std::rend(c));
+    cend(const C& c) NOTHROW(std::rend(c)) -> decltype(std::rend(c));
 #endif // C++14
 }