public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc/devel/ranger] libstdc++: Implement LWG 3150 for std::uniform_random_bit_generator
Date: Wed, 17 Jun 2020 18:53:52 +0000 (GMT)	[thread overview]
Message-ID: <20200617185352.028373953421@sourceware.org> (raw)

https://gcc.gnu.org/g:5b1d588509551291f4028497858ee9e04ce0bdee

commit 5b1d588509551291f4028497858ee9e04ce0bdee
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Feb 15 08:58:43 2020 +0000

    libstdc++: Implement LWG 3150 for std::uniform_random_bit_generator
    
            * include/bits/random.h (uniform_random_bit_generator): Require min()
            and max() to be constant expressions and min() to be less than max().
            * testsuite/26_numerics/random/concept.cc: Check additional cases.
            * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.

Diff:
---
 libstdc++-v3/ChangeLog                             |  7 ++++++
 libstdc++-v3/include/bits/random.h                 |  1 +
 .../testsuite/26_numerics/random/concept.cc        | 27 ++++++++++++++++++++++
 .../testsuite/26_numerics/random/pr60037-neg.cc    |  2 +-
 4 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index d1e5aad1b68..8e248703430 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,10 @@
+2020-02-15  Jonathan Wakely  <jwakely@redhat.com>
+
+	* include/bits/random.h (uniform_random_bit_generator): Require min()
+	and max() to be constant expressions and min() to be less than max().
+	* testsuite/26_numerics/random/concept.cc: Check additional cases.
+	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.
+
 2020-02-13  Patrick Palka  <ppalka@redhat.com>
 
 	* include/Makefile.am: Add <bits/ranges_uninitialized.h>.
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index 3eefdefc96f..d4aebf45af0 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -60,6 +60,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
 	{ _Gen::min() } -> same_as<invoke_result_t<_Gen&>>;
 	{ _Gen::max() } -> same_as<invoke_result_t<_Gen&>>;
+	requires bool_constant<(_Gen::min() < _Gen::max())>::value;
       };
 #endif
 
diff --git a/libstdc++-v3/testsuite/26_numerics/random/concept.cc b/libstdc++-v3/testsuite/26_numerics/random/concept.cc
index 69a7fc1e674..cb1ea882e16 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/concept.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/concept.cc
@@ -219,3 +219,30 @@ struct N11
 };
 
 static_assert( ! std::uniform_random_bit_generator<N11> );
+
+struct N12
+{
+  unsigned operator()();
+  static unsigned min() { return 0; } // not constexpr
+  static constexpr unsigned max() { return 1; }
+};
+
+static_assert( ! std::uniform_random_bit_generator<N12> ); // LWG 3150
+
+struct N13
+{
+  unsigned operator()();
+  static constexpr unsigned min() { return 0; }
+  static unsigned max() { return 1; } // not constexpr
+};
+
+static_assert( ! std::uniform_random_bit_generator<N13> ); // LWG 3150
+
+struct N14
+{
+  unsigned operator()();
+  static constexpr unsigned min() { return 1; }
+  static constexpr unsigned max() { return 0; } // max not greater than min
+};
+
+static_assert( ! std::uniform_random_bit_generator<N14> ); // LWG 3150
diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
index 201b87e9c52..91e5566c54a 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
@@ -10,6 +10,6 @@ std::__detail::_Adaptor<std::mt19937, unsigned long> aurng(urng);
 auto x = std::generate_canonical<std::size_t,
 			std::numeric_limits<std::size_t>::digits>(urng);
 
-// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 171 }
+// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 172 }
 
 // { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3281 }


                 reply	other threads:[~2020-06-17 18:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200617185352.028373953421@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).