This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
<future> vs -fno-exceptions
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 18 Dec 2009 21:50:04 +0000
- Subject: <future> vs -fno-exceptions
Although I'm updating <future> I'm not implementing the idea below,
I'm sending this mail just so the info is archived.
With -fno-exceptions std::copy_exception() does nothing, which seems
reasonable (although maybe it should return an empty exception_ptr)
std::promise::set_exception() uses std::copy_exception(), so with
-fno-exceptions that will store an empty exception_ptr. When you call
get() on an associated future the future will see the exception_ptr is
empty and then try to return a non-existent value, invoking undefined
behaviour.
It might be nice if -fno-exceptions caused futures to use a boolean
flag instead of an exception_ptr, so that calling
promise::set_exception() sets the flag and future::get() aborts if the
flag is set. That would mean an error could still be stored for later,
and would only abort if someone checks the result. That would make
promises and futures usable even with exceptions disabled.