crash.cc: ---- #include <boost/lexical_cast.hpp> #include <boost/date_time/posix_time/posix_time.hpp> int main() { boost::lexical_cast<int>( boost::gregorian::date(1969, boost::gregorian::Jul, 21).month() ); } ---- [08/06/2003 Wed 12:39.25 PM stl@nuwen ~/temp] > g++ --version g++ (GCC) 3.3 Copyright (C) 2003 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [08/06/2003 Wed 12:39.27 PM stl@nuwen ~/temp] > g++ -Wall -W crash.cc -o crash [08/06/2003 Wed 12:39.42 PM stl@nuwen ~/temp] > crash Segmentation fault [08/06/2003 Wed 12:39.54 PM stl@nuwen ~/temp] > 3.3 and 3.4-20030806 behave identically. I haven't tried any other versions. MinGW gcc 3.3 on WinXP also produces a segfaulting executable. The problem does not appear to be on Boost's end; I have been told that MSVC.NET 2003 compiles this correctly. I would submit preprocessed source, but it's about a megabyte. I've tried to reduce the test case as much as possible, but it seems that anything more eliminates the segfault. The workaround is to lexical_cast<whatever, int> instead of lexical_cast<whatever>. I originally encountered this problem when using lexical_cast<string> but I have changed it to lexical_cast<int> as above to demonstrate that this is not related to some quirk of string. Stepping through the program's execution with gdb: ---- (gdb) 0x080497ef in boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base <boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned long>::from_day_number(unsigned long) (dayNumber=2440424) at gregorian_calendar.ipp:125 125 return ymd_type(year,month,day); (gdb) boost::date_time::date<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::date_time::date_duration<long> >::month() const (this=0xbfffdbbc) at date.hpp:81 81 return ymd.month; (gdb) Program received signal SIGSEGV, Segmentation fault. 0x08049d56 in std::ios_base::getloc() const (this=0xbfffdb04) at ios_base.h:614 614 getloc() const { return _M_ios_locale; } (gdb) ---- Sometimes the segfault occurs elsewhere: ---- Program received signal SIGSEGV, Segmentation fault. 0x080498fa in operator<< <char, std::char_traits<char> > (os=@0xbfffe928, m=@0xbfffea20) at greg_facet.hpp:58 58 std::locale locale = os.getloc(); ----
Wee need the preprocessed file as not every one has boost install? Can you provide both the 3.3 one and the 3.4 one. Use gzip or bzip2 if you want the size to go down.
Created attachment 4573 [details] 3.3 preprocessed source
Created attachment 4574 [details] 3.4 preprocessed source
From looking at the code: template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const greg_month& m) { typedef boost::date_time::ostream_month_formatter<greg_base_facet, charT> greg_month_formatter; std::locale locale = os.getloc(); if (std::has_facet<greg_base_facet>(locale)) { const greg_base_facet& f = std::use_facet<greg_base_facet>(locale); greg_month_formatter::format_month(m, os, f); } else { os << std::setw(2) << std::setfill('0') << m; //this line } return os; } The problem there is stack overflow that is causing the seg fault but that is because the line marked this line is calling the same function over and over. I do not know if this is a boost problem or libstdc++ problem (becuase I do not like locals at all and I do not know them).
Marking this as invalid to mark it as ...
Unconfirmed.
Can a libstdc++ export look at this one because I think boost's code is not doing what they think it should do?
Is this related? http://lists.boost.org/MailArchives/boost/msg51572.php It looks like this may be Boost's fault, not gcc's. But I don't know enough about Boost internals or locales to really know.
It is the same bug, as I looked at why the seg fault happening before but I still do not know if it is boost's bug or ours, GCC.
It turns out that this is boost's bug. See: http://lists.boost.org/MailArchives/boost/msg52323.php This bug can be closed (as INVALID?). Thanks.
Not GCC bug but rather a boost bug.