This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11838] New: boost::lexical_cast segfault


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11838

           Summary: boost::lexical_cast segfault
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: stl at caltech dot edu
                CC: gcc-bugs at gcc dot gnu dot org

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();
----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]