[libcxx-commits] [libcxx] 7624552 - [libc++] Explicitly reject URNG types with signed result_types.
Arthur O'Dwyer via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 2 07:29:25 PST 2022
Author: Arthur O'Dwyer
Date: 2022-03-02T10:28:48-05:00
New Revision: 7624552ead284206ba63b4632eb2739c0d063d92
URL: https://github.com/llvm/llvm-project/commit/7624552ead284206ba63b4632eb2739c0d063d92
DIFF: https://github.com/llvm/llvm-project/commit/7624552ead284206ba63b4632eb2739c0d063d92.diff
LOG: [libc++] Explicitly reject URNG types with signed result_types.
Fixes #48965.
Differential Revision: https://reviews.llvm.org/D120630
Added:
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/bad_engine.verify.cpp
libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/bad_engine.verify.cpp
Modified:
libcxx/include/__random/bernoulli_distribution.h
libcxx/include/__random/binomial_distribution.h
libcxx/include/__random/cauchy_distribution.h
libcxx/include/__random/discrete_distribution.h
libcxx/include/__random/exponential_distribution.h
libcxx/include/__random/extreme_value_distribution.h
libcxx/include/__random/fisher_f_distribution.h
libcxx/include/__random/gamma_distribution.h
libcxx/include/__random/is_valid.h
libcxx/include/__random/negative_binomial_distribution.h
libcxx/include/__random/normal_distribution.h
libcxx/include/__random/piecewise_constant_distribution.h
libcxx/include/__random/piecewise_linear_distribution.h
libcxx/include/__random/poisson_distribution.h
libcxx/include/__random/student_t_distribution.h
libcxx/include/__random/uniform_int_distribution.h
libcxx/include/__random/uniform_real_distribution.h
Removed:
################################################################################
diff --git a/libcxx/include/__random/bernoulli_distribution.h b/libcxx/include/__random/bernoulli_distribution.h
index cf019519ab7f4..e97d53f5a4210 100644
--- a/libcxx/include/__random/bernoulli_distribution.h
+++ b/libcxx/include/__random/bernoulli_distribution.h
@@ -10,6 +10,7 @@
#define _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H
#include <__config>
+#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <iosfwd>
@@ -103,6 +104,7 @@ inline
bernoulli_distribution::result_type
bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
uniform_real_distribution<double> __gen;
return __gen(__g) < __p.p();
}
diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h
index 774f9d0bba305..d0e8f30349392 100644
--- a/libcxx/include/__random/binomial_distribution.h
+++ b/libcxx/include/__random/binomial_distribution.h
@@ -148,6 +148,7 @@ template<class _URNG>
_IntType
binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
if (__pr.__t_ == 0 || __pr.__p_ == 0)
return 0;
if (__pr.__p_ == 1)
diff --git a/libcxx/include/__random/cauchy_distribution.h b/libcxx/include/__random/cauchy_distribution.h
index 288118e1d22db..5bc44ee8dd4ca 100644
--- a/libcxx/include/__random/cauchy_distribution.h
+++ b/libcxx/include/__random/cauchy_distribution.h
@@ -10,6 +10,7 @@
#define _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H
#include <__config>
+#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <cmath>
#include <iosfwd>
@@ -116,6 +117,7 @@ inline
_RealType
cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
uniform_real_distribution<result_type> __gen;
// purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g));
diff --git a/libcxx/include/__random/discrete_distribution.h b/libcxx/include/__random/discrete_distribution.h
index bd47b8b46539c..d899e72d87f96 100644
--- a/libcxx/include/__random/discrete_distribution.h
+++ b/libcxx/include/__random/discrete_distribution.h
@@ -213,6 +213,7 @@ template<class _URNG>
_IntType
discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
uniform_real_distribution<double> __gen;
return static_cast<_IntType>(
_VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) -
diff --git a/libcxx/include/__random/exponential_distribution.h b/libcxx/include/__random/exponential_distribution.h
index e51871dd53bc3..1c9e9e0d9ef1b 100644
--- a/libcxx/include/__random/exponential_distribution.h
+++ b/libcxx/include/__random/exponential_distribution.h
@@ -11,6 +11,7 @@
#include <__config>
#include <__random/generate_canonical.h>
+#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <cmath>
#include <iosfwd>
@@ -109,6 +110,7 @@ template<class _URNG>
_RealType
exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
return -_VSTD::log
(
result_type(1) -
diff --git a/libcxx/include/__random/extreme_value_distribution.h b/libcxx/include/__random/extreme_value_distribution.h
index 15cebd8e95649..ba30aa5b88c31 100644
--- a/libcxx/include/__random/extreme_value_distribution.h
+++ b/libcxx/include/__random/extreme_value_distribution.h
@@ -10,6 +10,7 @@
#define _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H
#include <__config>
+#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <cmath>
#include <iosfwd>
@@ -116,6 +117,7 @@ template<class _URNG>
_RealType
extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
return __p.a() - __p.b() *
_VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g)));
}
diff --git a/libcxx/include/__random/fisher_f_distribution.h b/libcxx/include/__random/fisher_f_distribution.h
index 72f1f40aaa493..60c7f28c0bb0f 100644
--- a/libcxx/include/__random/fisher_f_distribution.h
+++ b/libcxx/include/__random/fisher_f_distribution.h
@@ -11,6 +11,7 @@
#include <__config>
#include <__random/gamma_distribution.h>
+#include <__random/is_valid.h>
#include <iosfwd>
#include <limits>
@@ -114,6 +115,7 @@ template<class _URNG>
_RealType
fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
diff --git a/libcxx/include/__random/gamma_distribution.h b/libcxx/include/__random/gamma_distribution.h
index a8504961b2881..986d79b67aa33 100644
--- a/libcxx/include/__random/gamma_distribution.h
+++ b/libcxx/include/__random/gamma_distribution.h
@@ -11,6 +11,7 @@
#include <__config>
#include <__random/exponential_distribution.h>
+#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <cmath>
#include <iosfwd>
@@ -117,6 +118,7 @@ template<class _URNG>
_RealType
gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
result_type __a = __p.alpha();
uniform_real_distribution<result_type> __gen(0, 1);
exponential_distribution<result_type> __egen;
diff --git a/libcxx/include/__random/is_valid.h b/libcxx/include/__random/is_valid.h
index 553f5dde80f09..d41bfa45ea70d 100644
--- a/libcxx/include/__random/is_valid.h
+++ b/libcxx/include/__random/is_valid.h
@@ -14,7 +14,6 @@
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
-# pragma clang include_instead(<random>)
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -40,6 +39,20 @@ template<> struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {};
template<> struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {};
#endif // _LIBCPP_HAS_NO_INT128
+// [rand.req.urng]/3:
+// A class G meets the uniform random bit generator requirements if G models
+// uniform_random_bit_generator, invoke_result_t<G&> is an unsigned integer type,
+// and G provides a nested typedef-name result_type that denotes the same type
+// as invoke_result_t<G&>.
+// (In particular, reject URNGs with signed result_types; our distributions cannot
+// handle such generator types.)
+
+template<class, class = void> struct __libcpp_random_is_valid_urng : false_type {};
+template<class _Gp> struct __libcpp_random_is_valid_urng<_Gp, __enable_if_t<
+ is_unsigned<typename _Gp::result_type>::value &&
+ _IsSame<decltype(declval<_Gp&>()()), typename _Gp::result_type>::value
+> > : true_type {};
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___RANDOM_IS_VALID_H
diff --git a/libcxx/include/__random/negative_binomial_distribution.h b/libcxx/include/__random/negative_binomial_distribution.h
index a4b96fb5f33f4..72ce88ea74ba9 100644
--- a/libcxx/include/__random/negative_binomial_distribution.h
+++ b/libcxx/include/__random/negative_binomial_distribution.h
@@ -118,6 +118,7 @@ template<class _URNG>
_IntType
negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
result_type __k = __pr.k();
double __p = __pr.p();
if (__k <= 21 * __p)
diff --git a/libcxx/include/__random/normal_distribution.h b/libcxx/include/__random/normal_distribution.h
index dc4de78e9273c..0431df9272001 100644
--- a/libcxx/include/__random/normal_distribution.h
+++ b/libcxx/include/__random/normal_distribution.h
@@ -10,6 +10,7 @@
#define _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H
#include <__config>
+#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <cmath>
#include <iosfwd>
@@ -131,6 +132,7 @@ template<class _URNG>
_RealType
normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
result_type _Up;
if (_V_hot_)
{
diff --git a/libcxx/include/__random/piecewise_constant_distribution.h b/libcxx/include/__random/piecewise_constant_distribution.h
index eec9b7540a968..a33ab0720062a 100644
--- a/libcxx/include/__random/piecewise_constant_distribution.h
+++ b/libcxx/include/__random/piecewise_constant_distribution.h
@@ -11,6 +11,7 @@
#include <__algorithm/upper_bound.h>
#include <__config>
+#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <iosfwd>
#include <numeric>
@@ -284,6 +285,7 @@ template<class _URNG>
_RealType
piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
typedef uniform_real_distribution<result_type> _Gen;
result_type __u = _Gen()(__g);
ptr
diff _t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
diff --git a/libcxx/include/__random/piecewise_linear_distribution.h b/libcxx/include/__random/piecewise_linear_distribution.h
index 0d7591af10565..e69ce94440723 100644
--- a/libcxx/include/__random/piecewise_linear_distribution.h
+++ b/libcxx/include/__random/piecewise_linear_distribution.h
@@ -11,6 +11,7 @@
#include <__algorithm/upper_bound.h>
#include <__config>
+#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <iosfwd>
#include <numeric>
@@ -289,6 +290,7 @@ template<class _URNG>
_RealType
piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
typedef uniform_real_distribution<result_type> _Gen;
result_type __u = _Gen()(__g);
ptr
diff _t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
diff --git a/libcxx/include/__random/poisson_distribution.h b/libcxx/include/__random/poisson_distribution.h
index 32f5223d0650c..7730923ad6ca1 100644
--- a/libcxx/include/__random/poisson_distribution.h
+++ b/libcxx/include/__random/poisson_distribution.h
@@ -159,6 +159,7 @@ template<class _URNG>
_IntType
poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
double __tx;
uniform_real_distribution<double> __urd;
if (__pr.__mean_ < 10)
diff --git a/libcxx/include/__random/student_t_distribution.h b/libcxx/include/__random/student_t_distribution.h
index dc38a8b3d2f8e..9e95f97cefabe 100644
--- a/libcxx/include/__random/student_t_distribution.h
+++ b/libcxx/include/__random/student_t_distribution.h
@@ -11,6 +11,7 @@
#include <__config>
#include <__random/gamma_distribution.h>
+#include <__random/is_valid.h>
#include <__random/normal_distribution.h>
#include <cmath>
#include <iosfwd>
@@ -111,6 +112,7 @@ template<class _URNG>
_RealType
student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
gamma_distribution<result_type> __gd(__p.n() * .5, 2);
return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g));
}
diff --git a/libcxx/include/__random/uniform_int_distribution.h b/libcxx/include/__random/uniform_int_distribution.h
index 70cf698b187a7..dd0a7e4e49828 100644
--- a/libcxx/include/__random/uniform_int_distribution.h
+++ b/libcxx/include/__random/uniform_int_distribution.h
@@ -232,6 +232,7 @@ typename uniform_int_distribution<_IntType>::result_type
uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t), uint32_t,
typename make_unsigned<result_type>::type>::type _UIntType;
const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1);
diff --git a/libcxx/include/__random/uniform_real_distribution.h b/libcxx/include/__random/uniform_real_distribution.h
index e11222540b47e..7d2ecda732fed 100644
--- a/libcxx/include/__random/uniform_real_distribution.h
+++ b/libcxx/include/__random/uniform_real_distribution.h
@@ -11,6 +11,7 @@
#include <__config>
#include <__random/generate_canonical.h>
+#include <__random/is_valid.h>
#include <iosfwd>
#include <limits>
#include <type_traits>
@@ -115,6 +116,7 @@ inline
typename uniform_real_distribution<_RealType>::result_type
uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
{
+ static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
return (__p.b() - __p.a())
* _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
+ __p.a();
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..822411415d6ee
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bernoulli/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::bernoulli_distribution dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..6680ea80d8228
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::binomial_distribution<int> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..5f925de923631
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::geometric_distribution<int> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 7 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..ee54e6b89c969
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.negbin/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::negative_binomial_distribution<int> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 7 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..76d50e9eae3ae
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.cauchy/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::cauchy_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..7ef4c2869c8bb
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.chisq/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::chi_squared_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 3 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..bc8ba7cdca787
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::fisher_f_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 4 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..c78ae61cf016b
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::lognormal_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..d865ab150a199
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::normal_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..71bc832581b8d
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::student_t_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 5 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..9214a83fc755d
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.exp/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::exponential_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..4b4bdd0673005
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::extreme_value_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..e0552616087d9
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::gamma_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 3 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..5dcaed3465490
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.poisson/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::poisson_distribution<int> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 4 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..8d1f11376c900
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.weibull/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::weibull_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..d4172e770f724
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.discrete/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::discrete_distribution<int> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..47f1caa34f777
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::piecewise_constant_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..9f0422d45b7e7
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::piecewise_linear_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* 2 {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..41a5408f059d1
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::uniform_int_distribution<int> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
diff --git a/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/bad_engine.verify.cpp b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/bad_engine.verify.cpp
new file mode 100644
index 0000000000000..38f91f9267cdb
--- /dev/null
+++ b/libcxx/test/libcxx/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/bad_engine.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <random>
+
+#include <random>
+
+template<class Int>
+struct G {
+ using result_type = Int;
+ result_type operator()();
+ static constexpr result_type min() { return 0; }
+ static constexpr result_type max() { return 255; }
+};
+
+void test(std::uniform_real_distribution<double> dist)
+{
+ G<int> badg;
+ G<unsigned> okg;
+
+ dist(badg); //expected-error@*:* {{static_assert failed}} //expected-note {{in instantiation}}
+ dist(okg);
+}
More information about the libcxx-commits
mailing list