From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 2/2] libstdc++: Simplify std::normal_distribution equality operator
Date: Fri, 6 May 2022 23:56:59 +0100 [thread overview]
Message-ID: <20220506225659.3368784-2-jwakely@redhat.com> (raw)
In-Reply-To: <20220506225659.3368784-1-jwakely@redhat.com>
Tested powerpc64le-linux, pushed to trunk.
-- >8 --
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 | 10 +---------
.../normal_distribution/operators/equal.cc | 20 +++++++++++++++++++
.../26_numerics/random/pr60037-neg.cc | 2 +-
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
index 87a16a21336..cb1d3675783 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -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;
}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc
index a3435232961..81534e95797 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/equal.cc
@@ -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;
}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
index 3ab9c44232e..c58f480640f 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
@@ -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 }
--
2.34.1
prev parent reply other threads:[~2022-05-06 22:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-06 22:56 [committed 1/2] libstdc++: Fix deserialization for std::normal_distribution [PR105502] Jonathan Wakely
2022-05-06 22:56 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220506225659.3368784-2-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).