id summary reporter owner description type status milestone component version severity resolution keywords cc 11633 chrono IO V1 may throw bad_cast Sébastien Barthélémy viboes "I had occurences of chrono io throwing bad_cast exceptions, which lead to backtraces like this one: {{{ #0 0x00007ffff54fda30 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 #1 0x00007ffff554f2a2 in std::__throw_bad_cast() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 #2 0x00007ffff2289bab in std::use_facet > (__loc=...) at /usr/include/c++/4.8/bits/locale_classes.tcc:137 #3 0x00007ffff2288c61 in boost::chrono::operator<< , boost::rational, boost::ratio<1l, 1l> > (os=..., d=...) at /home/sbarthelemy/.local/share/qi/toolchains/linux64/boost/include/boost/chrono/io_v1/chrono_io.hpp:210 }}} I think the attached minimal example reproduces the issue. Here the compile & run log using boost 1.58 {{{ $ make clean && make test rm -f src/*.o src/chrono_io clang++ -std=c++11 -c -g -fPIC -Iinclude -I/usr/include -o src/chrono_io.o src/chrono_io.cc clang++ -std=c++11 -rdynamic -Lsrc -o src/chrono_io src/chrono_io.o -lboost_chrono -lboost_system -lpthread -L/usr/lib/x86_64-linux-gnu LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu ./src/chrono_io terminate called after throwing an instance of 'std::bad_cast' what(): std::bad_cast Aborted (core dumped) Makefile:13: recipe for target 'test' failed make: *** [test] Error 13 }}} Here is the code around boost/include/boost/chrono/io_v1/chrono_io.hpp:210 {{{ template std::basic_ostream& operator<<(std::basic_ostream& os, const duration& d) { typedef duration_punct Facet; std::locale loc = os.getloc(); if (!std::has_facet(loc)) os.imbue(std::locale(loc, new Facet)); const Facet& f = std::use_facet(os.getloc()); //<<<<<<< line210, throw here return os << d.count() << ' ' << f.template name(d.count()); } }}} maybe we could avoid calling os.getloc() again at line 210 to avoid the race?" Support Requests assigned To Be Determined chrono Boost 1.58.0 Problem