Blame SOURCES/gcc8-pr105502.patch

2df340
From b005000525ab0a5116d21217c41fb1da5bd03796 Mon Sep 17 00:00:00 2001
2df340
From: Jonathan Wakely <jwakely@redhat.com>
2df340
Date: Fri, 6 May 2022 21:19:17 +0100
2df340
Subject: [PATCH] libstdc++: Fix deserialization for std::normal_distribution
2df340
 [PR105502]
2df340
2df340
This fixes a regression in std::normal_distribution deserialization that
2df340
caused the object to be left unchanged if the __state_avail value read
2df340
from the stream was false.
2df340
2df340
libstdc++-v3/ChangeLog:
2df340
2df340
	PR libstdc++/105502
2df340
	* include/bits/random.tcc
2df340
	(operator>>(basic_istream<C,T>&, normal_distribution<R>&)):
2df340
	Update state when __state_avail is false.
2df340
	* testsuite/26_numerics/random/normal_distribution/operators/serialize.cc:
2df340
	Check that deserialized object equals serialized one.
2df340
2df340
(cherry picked from commit 909ef4e2727ddc50a32d6ad379a1f1ccc1043c6a)
2df340
---
2df340
 libstdc++-v3/include/bits/random.tcc          |  2 +-
2df340
 .../operators/serialize.cc                    | 36 ++++++++++++++++++-
2df340
 2 files changed, 36 insertions(+), 2 deletions(-)
2df340
2df340
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
2df340
index 0a299baedc5..0f758671f69 100644
2df340
--- a/libstdc++-v3/include/bits/random.tcc
2df340
+++ b/libstdc++-v3/include/bits/random.tcc
2df340
@@ -1941,7 +1941,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
2df340
       bool __saved_avail;
2df340
       if (__is >> __mean >> __stddev >> __saved_avail)
2df340
 	{
2df340
-	  if (__saved_avail && (__is >> __x._M_saved))
2df340
+	  if (!__saved_avail || (__is >> __x._M_saved))
2df340
 	    {
2df340
 	      __x._M_saved_available = __saved_avail;
2df340
 	      __x.param(typename normal_distribution<_RealType>::
2df340
diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc
2df340
index a65d4004161..8cc70886bc7 100644
2df340
--- a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc
2df340
+++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc
2df340
@@ -25,6 +25,7 @@
2df340
 
2df340
 #include <random>
2df340
 #include <sstream>
2df340
+#include <testsuite_hooks.h>
2df340
 
2df340
 void
2df340
 test01()
2df340
@@ -37,10 +38,43 @@ test01()
2df340
   str << u;
2df340
 
2df340
   str >> v;
2df340
+  VERIFY( u == v );
2df340
+}
2df340
+
2df340
+void
2df340
+test_pr105502()
2df340
+{
2df340
+  // PR libstdc++/105502 std::normal_distribution deserialization issue
2df340
+  std::stringstream str;
2df340
+  std::normal_distribution<> d{1, 2}, d2;
2df340
+  std::minstd_rand0 g;
2df340
+  str << d;
2df340
+  VERIFY( str );
2df340
+  str >> d2;
2df340
+  VERIFY( str );
2df340
+  VERIFY( d == d2 );
2df340
+
2df340
+  (void) d(g); // sets d._M_saved_available = true
2df340
+  str.str("");
2df340
+  str.clear();
2df340
+  str << d;
2df340
+  VERIFY( str );
2df340
+  str >> d2;
2df340
+  VERIFY( str );
2df340
+  VERIFY( d == d2 );
2df340
+
2df340
+  (void) d(g); // sets d._M_saved_available = false
2df340
+  str.str("");
2df340
+  str.clear();
2df340
+  str << d;
2df340
+  VERIFY( str );
2df340
+  str >> d2;
2df340
+  VERIFY( str );
2df340
+  VERIFY( d == d2 );
2df340
 }
2df340
 
2df340
 int main()
2df340
 {
2df340
   test01();
2df340
-  return 0;
2df340
+  test_pr105502();
2df340
 }
2df340
-- 
2df340
2.31.1
2df340