Boost logo

Boost :

Subject: Re: [boost] Any-Range containing transformed range fails when compiled with optimizations
From: Seth (bugs_at_[hidden])
Date: 2016-01-15 08:08:26


On 15-01-16 09:04, Auer, Jens wrote:
> I've made some more investigations. I modified the program slightly to be able to compile it with older gcc and boost versions to see when it broke. Our project uses gcc 4.9.2 with boost 1.55, but when one of my colleagues compiled it on his local machine with gcc 5.2 and boost 1.59 we started to see the issues.
I made a version of the code that's c++03 safe and still exhibits the
problem on all clang/gcc versions I own.

Sadly I can't download boost 1.55 (sf.net is down) and modular boost
doesn't seem to be able to build (headers) in the 1.55 tag...

So maybe you can try this for a spin:

    #include <vector>
    #include <boost/range.hpp>
    #include <boost/range/any_range.hpp>
    #include <boost/range/adaptor/transformed.hpp>
    #include <iostream>

    static bool ok = true;

    struct SourceEvent
    {
        unsigned event;
        void* ptr;
    };

    template <typename R>
    void test(R const& r) {
        ok &= (100u == boost::size(r));

        for (typename boost::range_iterator<R>::type it = boost::begin(r);
                it != boost::end(r);
                ++it)
        {
            ok &= (0u == it->event);
            ok &= (0 == it->ptr);
        }
    }

    struct Xfrm {
        typedef SourceEvent result_type;
        SourceEvent operator()(unsigned) const { SourceEvent se = {};
    return se; }
    } xfrm_;

    SourceEvent xfrm(unsigned) { SourceEvent se = {}; return se; }

    int main() {
        using boost::adaptors::transformed;
        typedef boost::any_range<SourceEvent,
    boost::forward_traversal_tag/*, SourceEvent, std::ptrdiff_t*/> R;

        std::vector<int> v(100, 0);

        test (v | transformed(xfrm_));
        test<R>(v | transformed(xfrm_));

        if (ok)
            std::cout << "OK" << std::endl;
        else
            std::cout << "FAIL" << std::endl;

        return ok?0:1;
    }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk