libstdc++: Implement LWG 3422 for std::seed_seq
authorJonathan Wakely <jwakely@redhat.com>
Tue, 22 Jun 2021 17:05:11 +0000 (18:05 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 22 Jun 2021 19:58:25 +0000 (20:58 +0100)
This ensures that the std::seed_seq initializer-list constructor will
not be used for list-initialization unless the initializers in the list
are integers. This allows list-initialization syntax to be used with a
pair of pointers and for that to use the appropriate constructor.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* include/bits/random.h (seed_seq): Constrain initializer-list
constructor.
* include/bits/random.tcc (seed_seq): Add template parameter.
* testsuite/26_numerics/random/seed_seq/cons/default.cc: Check
for noexcept.
* testsuite/26_numerics/random/seed_seq/cons/initlist.cc: Check
constraints.

libstdc++-v3/include/bits/random.h
libstdc++-v3/include/bits/random.tcc
libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/default.cc
libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/initlist.cc

index 0da013c..ed0d7a8 100644 (file)
@@ -6073,7 +6073,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : _M_v()
     { }
 
-    template<typename _IntType>
+    template<typename _IntType, typename = _Require<is_integral<_IntType>>>
       seed_seq(std::initializer_list<_IntType> __il);
 
     template<typename _InputIterator>
index 1357e18..8e2b702 100644 (file)
@@ -3231,7 +3231,7 @@ namespace __detail
     }
 
 
-  template<typename _IntType>
+  template<typename _IntType, typename>
     seed_seq::seed_seq(std::initializer_list<_IntType> __il)
     {
       for (auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
index 18f55e7..62434a6 100644 (file)
@@ -25,6 +25,9 @@
 #include <random>
 #include <testsuite_hooks.h>
 
+static_assert( std::is_nothrow_default_constructible<std::seed_seq>::value,
+              "LWG 3422" );
+
 void
 test01()
 {
@@ -34,7 +37,6 @@ test01()
   seq.generate(foo.begin(), foo.end());
 
   VERIFY( seq.size() == 0 );
-  //VERIFY();
 }
 
 int
index 44b855e..1ed9eb7 100644 (file)
@@ -36,6 +36,13 @@ test01()
   VERIFY( seq.size() == 10 );
 }
 
+void
+lwg3422()
+{
+  int i[32] = { };
+  std::seed_seq ss{i, i+32}; // LWG 3422
+}
+
 int main()
 {
   test01();