libstdc++/10132: filebuf destructor throws exceptions

peturr02@ru.is peturr02@ru.is
Tue Mar 18 14:06:00 GMT 2003


>Number:         10132
>Category:       libstdc++
>Synopsis:       filebuf destructor throws exceptions
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 18 12:16:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.2
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
The destructor of basic_filebuf calls basic_filebuf::close() without handling exceptions thrown by that function (close() calls use_facet and codecvt::out(), both of which may throw).
>How-To-Repeat:
See attachment.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="dtorbug.cc"
Content-Disposition: inline; filename="dtorbug.cc"

#include <fstream>
#include <locale>
#include <cwchar>

#undef NDEBUG
#include <cassert>

class MyEx
{
};

class Cvt : public std::codecvt<wchar_t, char, std::mbstate_t>
{
protected:
	virtual std::codecvt_base::result
	do_out(std::mbstate_t&, const wchar_t*, const wchar_t*,
	       const wchar_t*&, char*, char*, char*&) const
		{
			throw MyEx();
		}
};

int main()
{
	using namespace std;

	locale loc;
	loc = locale(loc, new Cvt);
	
	wfilebuf* fb = new wfilebuf;
	fb->pubimbue(loc);
	fb->open("tmp", ios_base::out);
	fb->sputc(L'a');
	
	try
	{
		delete fb;
	}
	catch (...)
	{
		assert(false);
	}

	return 0;
}



More information about the Gcc-bugs mailing list