Bug 58302 - compilation error : std::negative_binomial_distribution::operator(e, p)
Summary: compilation error : std::negative_binomial_distribution::operator(e, p)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.7.4
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-03 03:42 UTC by Akira Takahashi
Modified: 2013-09-03 10:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-09-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Akira Takahashi 2013-09-03 03:42:42 UTC
Follow code become compilation error:

#include <random>

int main()
{
  typedef std::negative_binomial_distribution<> dist_type;

  std::default_random_engine engine;

  dist_type dist;
  dist_type::param_type param(3, 0.5);

  int result = dist(engine, param); // compile error!
}


error description:

prog.cc: In function 'int main()':
prog.cc:12:7: warning: unused variable 'result' [-Wunused-variable]
   int result = dist(engine, param); // compile error!
       ^
In file included from /usr/local/gcc-head/include/c++/4.9.0/random:49:0,
                 from prog.cc:1:
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h: In instantiation of 'class std::gamma_distribution<int>':
/usr/local/gcc-head/include/c++/4.9.0/bits/random.tcc:1295:4:   required from 'std::negative_binomial_distribution<_IntType>::result_type std::negative_binomial_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&, const std::negative_binomial_distribution<_IntType>::param_type&) [with _UniformRandomNumberGenerator = std::linear_congruential_engine<long unsigned int, 16807ul, 0ul, 2147483647ul>; _IntType = int; std::negative_binomial_distribution<_IntType>::result_type = int]'
prog.cc:12:34:   required from here
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h:2504:7: error: static assertion failed: template argument not a floating point type
       static_assert(std::is_floating_point<_RealType>::value,
       ^
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h: In instantiation of 'class std::normal_distribution<int>':
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h:2699:45:   required from 'class std::gamma_distribution<int>'
/usr/local/gcc-head/include/c++/4.9.0/bits/random.tcc:1295:4:   required from 'std::negative_binomial_distribution<_IntType>::result_type std::negative_binomial_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&, const std::negative_binomial_distribution<_IntType>::param_type&) [with _UniformRandomNumberGenerator = std::linear_congruential_engine<long unsigned int, 16807ul, 0ul, 2147483647ul>; _IntType = int; std::negative_binomial_distribution<_IntType>::result_type = int]'
prog.cc:12:34:   required from here
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h:2087:7: error: static assertion failed: template argument not a floating point type
       static_assert(std::is_floating_point<_RealType>::value,
       ^
In file included from /usr/local/gcc-head/include/c++/4.9.0/random:51:0,
                 from prog.cc:1:
/usr/local/gcc-head/include/c++/4.9.0/bits/random.tcc: In instantiation of 'std::negative_binomial_distribution<_IntType>::result_type std::negative_binomial_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&, const std::negative_binomial_distribution<_IntType>::param_type&) [with _UniformRandomNumberGenerator = std::linear_congruential_engine<long unsigned int, 16807ul, 0ul, 2147483647ul>; _IntType = int; std::negative_binomial_distribution<_IntType>::result_type = int]':
prog.cc:12:34:   required from here
/usr/local/gcc-head/include/c++/4.9.0/bits/random.tcc:1298:64: error: no match for call to '(std::gamma_distribution<double>) (std::linear_congruential_engine<long unsigned int, 16807ul, 0ul, 2147483647ul>&, param_type)'
    _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
                                                                ^
In file included from /usr/local/gcc-head/include/c++/4.9.0/random:49:0,
                 from prog.cc:1:
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h:2502:11: note: candidates are:
     class gamma_distribution
           ^
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h:2619:2: note: template<class _UniformRandomNumberGenerator> std::gamma_distribution<_RealType>::result_type std::gamma_distribution<_RealType>::operator()(_UniformRandomNumberGenerator&) [with _UniformRandomNumberGenerator = _UniformRandomNumberGenerator; _RealType = double]
  operator()(_UniformRandomNumberGenerator& __urng)
  ^
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h:2619:2: note:   template argument deduction/substitution failed:
In file included from /usr/local/gcc-head/include/c++/4.9.0/random:51:0,
                 from prog.cc:1:
/usr/local/gcc-head/include/c++/4.9.0/bits/random.tcc:1298:64: note:   candidate expects 1 argument, 2 provided
    _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
                                                                ^
In file included from /usr/local/gcc-head/include/c++/4.9.0/random:49:0,
                 from prog.cc:1:
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h:2624:2: note: template<class _UniformRandomNumberGenerator> std::gamma_distribution<_RealType>::result_type std::gamma_distribution<_RealType>::operator()(_UniformRandomNumberGenerator&, const std::gamma_distribution<_RealType>::param_type&) [with _UniformRandomNumberGenerator = _UniformRandomNumberGenerator; _RealType = double]
  operator()(_UniformRandomNumberGenerator& __urng,
  ^
/usr/local/gcc-head/include/c++/4.9.0/bits/random.h:2624:2: note:   template argument deduction/substitution failed:
In file included from /usr/local/gcc-head/include/c++/4.9.0/random:51:0,
                 from prog.cc:1:
/usr/local/gcc-head/include/c++/4.9.0/bits/random.tcc:1298:64: note:   cannot convert 'std::gamma_distribution<int>::param_type((& __p)->std::negative_binomial_distribution<_IntType>::param_type::k<int>(), (int)(#'rdiv_expr' not supported by expression#))' (type 'param_type {aka std::gamma_distribution<int>::param_type}') to type 'const std::gamma_distribution<double>::param_type&'
    _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
Comment 1 Paolo Carlini 2013-09-03 09:06:49 UTC
Thanks. A pretty stupid typo, I'll fix it ASAP.
Comment 2 paolo@gcc.gnu.org 2013-09-03 10:12:21 UTC
Author: paolo
Date: Tue Sep  3 10:12:19 2013
New Revision: 202208

URL: http://gcc.gnu.org/viewcvs?rev=202208&root=gcc&view=rev
Log:
2013-09-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/58302
	* include/bits/random.tcc (negative_binomial_distribution<>::
	operator()(_UniformRandomNumberGenerator&, const param_type&):
	Fix typo in template argument.
	* testsuite/26_numerics/random/negative_binomial_distribution/
	operators/58302.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/58302.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/random.tcc
Comment 3 paolo@gcc.gnu.org 2013-09-03 10:12:46 UTC
Author: paolo
Date: Tue Sep  3 10:12:44 2013
New Revision: 202209

URL: http://gcc.gnu.org/viewcvs?rev=202209&root=gcc&view=rev
Log:
2013-09-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/58302
	* include/bits/random.tcc (negative_binomial_distribution<>::
	operator()(_UniformRandomNumberGenerator&, const param_type&):
	Fix typo in template argument.
	* testsuite/26_numerics/random/negative_binomial_distribution/
	operators/58302.cc: New.

Added:
    branches/gcc-4_8-branch/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/58302.cc
Modified:
    branches/gcc-4_8-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_8-branch/libstdc++-v3/include/bits/random.tcc
Comment 4 paolo@gcc.gnu.org 2013-09-03 10:19:18 UTC
Author: paolo
Date: Tue Sep  3 10:19:16 2013
New Revision: 202210

URL: http://gcc.gnu.org/viewcvs?rev=202210&root=gcc&view=rev
Log:
2013-09-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/58302
	* include/bits/random.tcc (negative_binomial_distribution<>::
	operator()(_UniformRandomNumberGenerator&, const param_type&):
	Fix typo in template argument.
	* testsuite/26_numerics/random/negative_binomial_distribution/
	operators/58302.cc: New.

Added:
    branches/gcc-4_7-branch/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/58302.cc
Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/include/bits/random.tcc
Comment 5 Paolo Carlini 2013-09-03 10:20:22 UTC
Fixed for 4.9.0/4.8.2/4.7.4.