Bug 71025 - std::call_once aborts instead of propagating an exception (AIX 6.1)
Summary: std::call_once aborts instead of propagating an exception (AIX 6.1)
Status: RESOLVED DUPLICATE of bug 66146
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 5.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-09 14:16 UTC by Vojtech Fried
Modified: 2016-05-09 18:31 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vojtech Fried 2016-05-09 14:16:13 UTC
When an exception is thrown inside a function called from std::call_once, the process is aborted. The exception should be propagated outside std::call_once.

#include <stdio.h>
#include <mutex>
#include <stdexcept>

int main()
{
	static std::once_flag flag;

	printf( "start\n" );
	try
	{
		std::call_once(
			flag,
			[&]()
			{
				throw std::runtime_error("thrown from once");
			} );
	}
	catch ( std::runtime_error const& exc )
	{
		printf( "%s\n", exc.what() );
	}
	printf( "end\n" );
	return 0;
}

bea@stbldap02:~/samples$ g++ -std=c++14 -pthread std_call_once_exception.cxx
bea@stbldap02:~/samples$ ./a.out
start
terminate called after throwing an instance of 'std::runtime_error'
  what():  thrown from once
IOT/Abort trap (core dumped)

BTW: the system on which I tested it should be the same as in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67478
Comment 1 Vojtech Fried 2016-05-09 14:38:41 UTC
I am sorry, probably duplicate of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146
Comment 2 Jonathan Wakely 2016-05-09 18:31:34 UTC
Yes this is PR 66146

*** This bug has been marked as a duplicate of bug 66146 ***