libstdc++: Fix noexcept-specifier for istream_iterator
authorJonathan Wakely <jwakely@redhat.com>
Mon, 24 Feb 2020 14:22:21 +0000 (14:22 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 24 Feb 2020 14:22:21 +0000 (14:22 +0000)
Somehow I missed that the _M_value member can throw on construction.

* include/bits/stream_iterator.h (istream_iterator(default_sentinel_t)):
Make noexcept-specifier conditional.
* testsuite/24_iterators/istream_iterator/cons/sentinel.cc: Check
noexcept-specifier.

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stream_iterator.h
libstdc++-v3/testsuite/24_iterators/istream_iterator/cons/sentinel.cc

index e18f9d073605fb22e1e753068e0b4911285438a5..eefb2a5bd42d56513724fbf90eb6dd5b6289964d 100644 (file)
@@ -1,5 +1,10 @@
 2020-02-24  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/bits/stream_iterator.h (istream_iterator(default_sentinel_t)):
+       Make noexcept-specifier conditional.
+       * testsuite/24_iterators/istream_iterator/cons/sentinel.cc: Check
+       noexcept-specifier.
+
        * include/bits/stream_iterator.h (istream_iterator(default_sentinel_t)):
        Add constructor.
        (operator==(istream_iterator, default_sentinel_t)): Add operator.
index 1ddf647f7290480934c44c17c4ae325515735bc4..9d8ead092b8eed31fafe8cf3024837dddddbdd08 100644 (file)
@@ -79,7 +79,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus > 201703L
       constexpr
-      istream_iterator(default_sentinel_t) noexcept
+      istream_iterator(default_sentinel_t)
+      noexcept(is_nothrow_default_constructible_v<_Tp>)
       : istream_iterator() { }
 #endif
 
index 77a19498817850e7b16ae0f625504da9ee8bd805..b890f04f8e93086a070a8efd281357a19344dfcc 100644 (file)
 // <http://www.gnu.org/licenses/>.
 
 #include <iterator>
+#include <istream>
 
 // C++20 doesn't require this to be non-throwing.
 static_assert( std::is_nothrow_constructible_v<std::istream_iterator<int>,
                                               std::default_sentinel_t> );
 
 constexpr std::istream_iterator<int> i = std::default_sentinel;
+
+struct X { X() noexcept(false); };
+std::istream& operator<<(std::istream&, X&);
+
+static_assert( std::is_constructible_v<std::istream_iterator<X>,
+                                      std::default_sentinel_t> );
+static_assert( ! std::is_nothrow_constructible_v<std::istream_iterator<X>,
+                                                std::default_sentinel_t> );