Boost logo

Boost Users :

Subject: [Boost-users] boost::mpl, c++11 and clang 3.0: compiler bug?
From: Allan Nielsen (a_at_[hidden])
Date: 2012-01-17 10:25:29


Hi

The following code compiles fine under clang 3.0 but I get unexpected output:

#include <iostream>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/vector.hpp>

template< typename _state >
struct AccSize{
    size_t s = 0;
    _state xxxx;

    template<typename T>
    void operator()(T) {
        std::cout << s << " " << sizeof(T) << std::endl;
        s += sizeof(T);
    };
};

struct Foo {
    Foo () {}
    Foo (const Foo & rhs) {}
};

struct A{};

int main(int argc, const char *argv[])
{
    using namespace std;

    AccSize < Foo > p;

    typedef boost::mpl::vector<int, int, int> list;
    boost::mpl::for_each< list >( p );

    return 0;
}

The output I get is:
0 4
0 4
0 4

The output I expected is:
0 4
4 4
8 4

If I remove the copy constructor in Foo, it works as I expect, and if
I do a "normal" initialization of AccSize::s it also works as I
expect.

Is this a bug? If so, how can it be reproduced without mpl::foreach

Best regards
Allan W. Nielsen


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net