This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag
- From: "chus_flores at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 01 Jan 2014 19:20:13 +0000
- Subject: [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59656
Bug ID: 59656
Summary: weak_ptr::lock function crashes when compiling with
-fno-exceptions flag
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: chus_flores at hotmail dot com
weak_ptr::lock crashes when the code is compiled with the -fno-exceptions flag
and the data pointed by the weak_ptr expires during the execution of the lock
function itself:
(from http://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01518_source.html)
shared_ptr<_Tp>
494 lock() const noexcept
495 {
496 #ifdef __GTHREADS
497 if (this->expired())
498 return shared_ptr<_Tp>();
499
500 __try
501 {
502 return shared_ptr<_Tp>(*this);
503 }
504 __catch(const bad_weak_ptr&)
505 {
506 return shared_ptr<_Tp>();
507 }
508 #else
509 return this->expired() ? shared_ptr<_Tp>() : shared_ptr<_Tp>(*this);
510 #endif
511 }
If the data is valid when line 497 is executed and the data is released in a
different thread just before executing line 502, the program will crash because
it will try to throw an exception (exceptions are disabled because of the flag
-fno-exceptions). This code only works when exceptions are enabled because the
try/catch will resolve the problem, but not otherwise.
The standard definition says that this function must return safely and it
doesn't throw any exception. I presume this must apply even if the exceptions
are not enabled.