Blame SOURCES/gcc8-pr105502.patch

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