forked from OSchip/llvm-project
[libc++] Explicitly reject URNG types with signed result_types.
Fixes #48965. Differential Revision: https://reviews.llvm.org/D120630
This commit is contained in:
parent
bcdc047731
commit
7624552ead
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)) -
|
||||
|
|
|
@ -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) -
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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_)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
|
||||
|
|
|
@ -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);
|
||||
ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue