diff --git a/libcxx/include/__random/bernoulli_distribution.h b/libcxx/include/__random/bernoulli_distribution.h --- 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 @@ -103,6 +104,7 @@ 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 __gen; return __gen(__g) < __p.p(); } diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h --- a/libcxx/include/__random/binomial_distribution.h +++ b/libcxx/include/__random/binomial_distribution.h @@ -148,6 +148,7 @@ _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 --- 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 #include @@ -116,6 +117,7 @@ _RealType cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { + static_assert(__libcpp_random_is_valid_urng<_URNG>::value, ""); uniform_real_distribution __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 --- a/libcxx/include/__random/discrete_distribution.h +++ b/libcxx/include/__random/discrete_distribution.h @@ -213,6 +213,7 @@ _IntType discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) { + static_assert(__libcpp_random_is_valid_urng<_URNG>::value, ""); uniform_real_distribution __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 --- 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 #include @@ -109,6 +110,7 @@ _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 --- 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 #include @@ -116,6 +117,7 @@ _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()(__g))); } diff --git a/libcxx/include/__random/fisher_f_distribution.h b/libcxx/include/__random/fisher_f_distribution.h --- 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 #include @@ -114,6 +115,7 @@ _RealType fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { + static_assert(__libcpp_random_is_valid_urng<_URNG>::value, ""); gamma_distribution __gdm(__p.m() * result_type(.5)); gamma_distribution __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 --- 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 #include @@ -117,6 +118,7 @@ _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 __gen(0, 1); exponential_distribution __egen; diff --git a/libcxx/include/__random/is_valid.h b/libcxx/include/__random/is_valid.h --- 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() #endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -40,6 +39,20 @@ 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 is an unsigned integer type, +// and G provides a nested typedef-name result_type that denotes the same type +// as invoke_result_t. +// (In particular, reject URNGs with signed result_types; our distributions cannot +// handle such generator types.) + +template struct __libcpp_random_is_valid_urng : false_type {}; +template struct __libcpp_random_is_valid_urng<_Gp, __enable_if_t< + is_unsigned::value && + _IsSame()()), 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 --- a/libcxx/include/__random/negative_binomial_distribution.h +++ b/libcxx/include/__random/negative_binomial_distribution.h @@ -118,6 +118,7 @@ _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 --- 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 #include @@ -131,6 +132,7 @@ _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 --- 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 #include @@ -284,6 +285,7 @@ _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 _Gen; result_type __u = _Gen()(__g); ptrdiff_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 --- 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 #include @@ -289,6 +290,7 @@ _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 _Gen; result_type __u = _Gen()(__g); ptrdiff_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 --- a/libcxx/include/__random/poisson_distribution.h +++ b/libcxx/include/__random/poisson_distribution.h @@ -159,6 +159,7 @@ _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 __urd; if (__pr.__mean_ < 10) diff --git a/libcxx/include/__random/student_t_distribution.h b/libcxx/include/__random/student_t_distribution.h --- 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 #include @@ -111,6 +112,7 @@ _RealType student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { + static_assert(__libcpp_random_is_valid_urng<_URNG>::value, ""); gamma_distribution __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 --- a/libcxx/include/__random/uniform_int_distribution.h +++ b/libcxx/include/__random/uniform_int_distribution.h @@ -232,6 +232,7 @@ 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::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 --- 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 #include #include @@ -115,6 +116,7 @@ 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 --- /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 + +// + +#include + +template +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 badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G 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 --- /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 + +// + +#include + +template +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 dist) +{ + G badg; + G okg; + + dist(badg); //expected-error@*:* {{static_assert failed}} //expected-note {{in instantiation}} + dist(okg); +}