]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Simplify std::normal_distribution equality operator
authorJonathan Wakely <jwakely@redhat.com>
Fri, 6 May 2022 20:37:47 +0000 (21:37 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 6 May 2022 22:54:09 +0000 (23:54 +0100)
libstdc++-v3/ChangeLog:

* include/bits/random.tcc (operator==): Only check
normal_distribution::_M_saved_available once.
* testsuite/26_numerics/random/normal_distribution/operators/equal.cc:
Check equality after state changes.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
lineno.

libstdc++-v3/include/bits/random.tcc
libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc
libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc

index 87a16a2133672f6df29066f31bff7ac2a1ab9a0c..cb1d3675783650550da390b06eb435983243ff5e 100644 (file)
@@ -1907,15 +1907,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       if (__d1._M_param == __d2._M_param
          && __d1._M_saved_available == __d2._M_saved_available)
-       {
-         if (__d1._M_saved_available
-             && __d1._M_saved == __d2._M_saved)
-           return true;
-         else if(!__d1._M_saved_available)
-           return true;
-         else
-           return false;
-       }
+       return __d1._M_saved_available ? __d1._M_saved == __d2._M_saved : true;
       else
        return false;
     }
index a3435232961191f095366c6f8657bd541fc66bcb..81534e95797921677d3b4075f08379212acc1c86 100644 (file)
@@ -34,8 +34,28 @@ test01()
   VERIFY( !(u == v) );
 }
 
+void
+test02()
+{
+  std::normal_distribution<double> u(5.0, 2.0), v(u);
+  VERIFY( u == v );
+  u.reset();
+  VERIFY( u == v );
+
+  std::minstd_rand0 g1, g2;
+  (void) u(g1); // u._M_saved_available = true
+  VERIFY( !(u == v) );
+  (void) v(g2); // v._M_saved_available = true
+  VERIFY( u == v );
+  u.reset();    // u._M_saved_available = false
+  VERIFY( !(u == v) );
+  v.reset();    // v._M_saved_available = false
+  VERIFY( u == v );
+}
+
 int main()
 {
   test01();
+  test02();
   return 0;
 }
index 3ab9c44232e3ebb1f134ca6b4a825ce7deebb496..c58f480640f63597921db92cc6617bd3349ff831 100644 (file)
@@ -12,4 +12,4 @@ auto x = std::generate_canonical<std::size_t,
 
 // { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 169 }
 
-// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3356 }
+// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3348 }