Creation of an fstream instance produces a segmentation fault if the global locale does not contain a ctype facet matching the template parameters of the filebuf instantiation. A bad_cast exception is thrown by a call to use_facet<> in the basic_filebuf constructor, and this causes the as yet, incomplete fstream instance to be destroyed. The actual fault appears to occur because the ios_base destructor calls ios_base::_M_call_callbacks before the _M_callbacks field has been initialized. This happens because basic_ios<>, as a virtual base class, is constructed before basic_ostream's constructor has called its init() method. This constructor is never executed because the bad_cast exception is produced while constructing the filebuf that would be supplied as its streambuf argument. This problem might also exist for other stream types. Release: gcc-3_0-branch Environment: Red Hat Linux 2.2.16 How-To-Repeat: Instantiate a basic_ofstream using a character type other than char or wchar_t, and construct an instance of that stream without changing the original global locale.
Fix: Not sure. May need to do go ahead and do initialization in default constructor.
From: benjamin kosnik <bkoz@nabi.net> To: gcc-gnats@gcc.gnu.org, bumgard@roguewave.com, nobody@gcc.gnu.org Cc: Subject: Re: libstdc++/2020 Date: Mon, 12 Mar 2001 15:13:06 -0800 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2020&database=gcc here's the testcase: // libstdc++/2020 #include <fstream> class gnu_char_type { unsigned long character; public: // operator == bool operator==(const gnu_char_type& __lhs) { return character == __lhs.character; } // operator < bool operator<(const gnu_char_type& __lhs) { return character < __lhs.character; } // to_char_type gnu_char_type(const unsigned long& __l) : character(__l) { } // to_int_type operator unsigned long() const { return character; } }; void test01() { typedef std::basic_filebuf<gnu_char_type> gnu_filebuf; gnu_filebuf obj; } int main() { test01(); return 0; }
From: benjamin kosnik <bkoz@nabi.net> To: gcc-gnats@gcc.gnu.org, bumgard@roguewave.com, nobody@gcc.gnu.org Cc: Subject: Re: libstdc++/2020 Date: Wed, 14 Mar 2001 12:48:53 -0800 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2020&database=gcc 2001-03-14 Benjamin Kosnik <bkoz@redhat.com> libstdc++/2020 * include/bits/std_streambuf.h: Remove cached locale facets. (basic_streambuf::_M_buf_fctype): Remove. (basic_streambuf::~basic_streambuf): Remove here. (basic_streambuf::basic_streambuf): Same. (basic_streambuf::imbue): Same. * include/bits/fstream.tcc (filebuf::imbue): Remove _M_buf_fctype. * include/bits/std_fstream.h (basic_filebuf::_M_fcvt): Remove. (basic_filebuf::~basic_filebuf()): Remove here. * include/bits/fstream.tcc (basic_filebuf::basic_filebuf): Same. (basic_filebuf::imbue): Same. * include/bits/localefwd.h (_Count_ones): Remove. (locale::_S_num_categories): Just use 6, since this doesn't actually change, ever. * include/bits/locale_facets.tcc (has_facet): Simplify. (use_facet): Same. * testsuite/27_io/filebuf.cc (test06): Add tests. Fixed. Please read the commit message here: http://gcc.gnu.org/ml/gcc-patches/2001-03/msg00977.html This is one more step on getting codecvt working in filebufs, more necessary. Which of your bugs are still outstanding? -benjamin
Responsible-Changed-From-To: unassigned->bkoz Responsible-Changed-Why: Fixed
State-Changed-From-To: open->closed State-Changed-Why: Fixed
From: bkoz@gcc.gnu.org To: bkoz@gcc.gnu.org, bumgard@roguewave.com, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: libstdc++/2020 Date: 14 Mar 2001 21:35:52 -0000 Synopsis: fstream initialization seg-faults if global locale is missing required facets Responsible-Changed-From-To: unassigned->bkoz Responsible-Changed-By: bkoz Responsible-Changed-When: Wed Mar 14 13:35:52 2001 Responsible-Changed-Why: Fixed State-Changed-From-To: open->closed State-Changed-By: bkoz State-Changed-When: Wed Mar 14 13:35:52 2001 State-Changed-Why: Fixed http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2020&database=gcc
The master branch has been updated by Andrew Stubbs <ams@gcc.gnu.org>: https://gcc.gnu.org/g:14e5e74698b98f4cbe398cb989dfa27765cbca6e commit r10-6173-g14e5e74698b98f4cbe398cb989dfa27765cbca6e Author: Andrew Stubbs <ams@codesourcery.com> Date: Wed Jan 22 17:56:54 2020 +0000 Fix libgomp plugin-gcn bug 2020-01-23 Andrew Stubbs <ams@codesourcery.com> libgomp/ * plugin/plugin-gcn.c (parse_target_attributes): Use correct mask for the device id.