id summary reporter owner description type status milestone component version severity resolution keywords cc 244 Bug in lexical_cast.hpp jfmeinel kevlin "{{{ In boost-1_31_0, I believe there is a typo in lexical_cast.hpp The line Target lexical_cast(Source arg) should be Target lexical_cast(Source& arg) Otherwise it actually creates a copy of the argument before doing the lexical cast. This causes problems if you try to lexical_cast() a virtual object. Here is code that shows the bug. By just adding the '&', the code performs as you would expect it to. #include #include #include struct A { virtual int f() const = 0; }; struct B : A { virtual int f() const { return 1; } }; struct C : B { virtual int f() const { return 2; } }; std::ostream& operator<<(std::ostream& os, const A& a) { return os << a.f(); } int main() { C c; std::string s; std::cout << c << std::endl; //This should print 2 s = boost::lexical_cast(c); std::cout << s << std::endl; //This should print 2 s = boost::lexical_cast(c); std::cout << s << std::endl; //This returns 1, not 2 //This fails because it tries to instantiate an object of type A. Why??? s = boost::lexical_cast(c); std::cout << s << std::endl; } }}}" Bugs closed lexical_cast None None