http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52540
Bug #: 52540 Summary: std::use_facet throws bad_cast when compiled with _GLIBCXX_DEBUG Classification: Unclassified Product: gcc Version: 4.6.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: pl...@agmk.net Target: x86_64-w64-mingw32 #include <iostream> #include <locale> #include <cstring> #include <ctime> int main() { std::tm tm; std::time_t tt; std::time( &tt ); tm = *std::localtime( &tt ); std::locale lc( "C" ); std::cout.imbue( lc ); std::time_put< char > const& timeFacet = std::use_facet< std::time_put< char > >( std::cout.getloc() ); char const pattern[] = "%x %X"; timeFacet.put( std::cout, std::cout, std::cout.fill(), &tm, pattern, pattern + std::strlen( pattern ) ); } $ x86_64-w64-mingw32-g++ main.cpp -o main-release.exe -g2 $ x86_64-w64-mingw32-g++ main.cpp -o main-debug.exe -g2 -D_GLIBCXX_DEBUG release-run: Starting program: main-release.exe [New Thread 2776.0xdbc] Breakpoint 1, main () at main.cpp:7 7 { (gdb) n 10 std::time( &tt ); (gdb) 11 tm = *std::localtime( &tt ); (gdb) 12 std::locale lc( "C" ); (gdb) 13 std::cout.imbue( lc ); (gdb) p lc $2 = {static none = 0, static ctype = 1, static numeric = 2, static collate = 4, static time = 8, static monetary = 16, static messages = 32, static all = 63, _M_impl = 0x626e9460, static _S_classic = 0x626e9460, static _S_global = 0x626e9460, static _S_categories = 0x626eadc0, static _S_once = {done = 1, started = 0}} (gdb) c Continuing. 03/09/12 11:53:50 Program exited normally. debug-run: Starting program: main-debug.exe [New Thread 2704.0xd4c] Breakpoint 1, main () at main.cpp:7 7 { (gdb) l 2 #include <locale> 3 #include <cstring> 4 #include <ctime> 5 6 int main() 7 { 8 std::tm tm; 9 std::time_t tt; 10 std::time( &tt ); 11 tm = *std::localtime( &tt ); (gdb) n 10 std::time( &tt ); (gdb) 11 tm = *std::localtime( &tt ); (gdb) 12 std::locale lc( "C" ); (gdb) 13 std::cout.imbue( lc ); (gdb) p lc $1 = {static none = 0, static ctype = 1, static numeric = 2, static collate = 4, static time = 8, static monetary = 16, static messages = 32, static all = 63, _M_impl = 0x626e9460, static _S_classic = 0x626e9460, static _S_global = 0x626e9460, static _S_categories = 0x626eadc0, static _S_once = {done = 1, started = 0}} (gdb) n 14 std::time_put< char > const& timeFacet = std::use_facet< std::time_put< char > >( std::cout.getloc() ); (gdb) terminate called after throwing an instance of 'std::bad_cast' what(): std::bad_cast