boost::mpl, c++11 and clang 3.0: compiler bug?

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

Allan Nielsen <a@awn.dk> writes:
The code works as expected (after removing the non-static member initializer) on gcc and this is the behaviour that is expected. To test without mpl::for_each just unroll the loop: AccSize < Foo > p; p(int()); p(int()); p(int());
Best regards Allan W. Nielsen
Cheers, Philipp Moeller

On Tue, Jan 17, 2012 at 4:45 PM, Philipp Moeller <philipp.moeller@geometryfactory.com> wrote:
I got a compile error on this, but tried the following instead: int i; AccSize < Foo > p; p(i); p(i); p(i); But as Sebastian can inform it works in Clang SVN-HEAD, then it is properly a bug in clang 3.0. Regards Allan W. Nielsen
participants (3)
-
Allan Nielsen
-
Philipp Moeller
-
Sebastian Redl