[LLVMbugs] [Bug 12577] New: <random> failed to compile due to non-standard assumption of the RNG

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Apr 17 10:36:09 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12577

             Bug #: 12577
           Summary: <random> failed to compile due to non-standard
                    assumption of the RNG
           Product: libc++
           Version: unspecified
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: zhouyan1014 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The Random123
(http://www.thesalmons.org/john/random123/releases/latest/docs/index.html)
library provide an RNG Engine that is supposed to be usable with C++11 <random>
library. However the following code failed to compile on Mac OS X 10.7, Xcode
4.3.2,

#include <iostream>
#include <random>
#include <Random123/threefry.h>
#include <Random123/conventional/Engine.hpp>

int main ()
{
    std::uniform_real_distribution<> runif(0,1);
    r123::Engine<r123::Threefry4x64> eng;

    std::cout << runif(eng) << std::endl;

    return 0;
}

It emits the following error, when compiled with
clang++ -std=c++11 -stdlib=libc++ -o test test.cpp

In file included from test.cpp:2:
/usr/bin/../lib/c++/v1/random:3524:51: error: no member named '_Max' in
'r123::Engine<r123::Threefry4x64_R<20> >'
    const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min +
uint64_t(1)>::value;
                                           ~~~~~~~^
/usr/bin/../lib/c++/v1/random:3655:11: note: in instantiation of function
template specialization 'std::__1::generate_canonical<double, 53,
      r123::Engine<r123::Threefry4x64_R<20> > >' requested here
        * _VSTD::generate_canonical<_RealType,
numeric_limits<_RealType>::digits>(__g)
          ^
/usr/bin/../lib/c++/v1/__config:251:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
              ^
/usr/bin/../lib/c++/v1/random:3619:17: note: in instantiation of function
template specialization
     
'std::__1::uniform_real_distribution<double>::operator()<r123::Engine<r123::Threefry4x64_R<20>
> >' requested here
        {return (*this)(__g, __p_);}
                ^
test.cpp:11:23: note: in instantiation of function template specialization
     
'std::__1::uniform_real_distribution<double>::operator()<r123::Engine<r123::Threefry4x64_R<20>
> >' requested here
    std::cout << runif(eng) << std::endl;
                      ^
In file included from test.cpp:2:
/usr/bin/../lib/c++/v1/random:3526:34: error: no member named '_Max' in
'r123::Engine<r123::Threefry4x64_R<20> >'
    const _RealType _Rp = _URNG::_Max - _URNG::_Min + _RealType(1);
                          ~~~~~~~^
/usr/bin/../lib/c++/v1/random:3528:36: error: no member named '_Min' in
'r123::Engine<r123::Threefry4x64_R<20> >'
    _RealType _Sp = __g() - _URNG::_Min;
                            ~~~~~~~^
3 errors generated.

It seems that the implementation assumes existence of attributes _Max and _Min,
etc. Though the standard only requires the Engine to have .max() and .min()
member functions.

The above code compiles without any problem with gcc-4.6.3 with -std=c++0x
flag. And the engine of Random123 can also be used without any problem with
Boost.Random, which provide similar functionality as C++11.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list