<future> vs -fno-exceptions
Jonathan Wakely
jwakely.gcc@gmail.com
Fri Dec 18 21:50:00 GMT 2009
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.
More information about the Libstdc++
mailing list