Does disabling support for exceptions also disable support for `std :: move_if_noexcept`?
Some stores (for example, some video game development teams) disable support for exceptions in their build environment. If exceptions were turned off, developers would have nothing to declare about their move operations noexcept
(assuming that such code would even compile). But when implementing some operations (for example std::vector::push_back
), standard library implementations must call std::move_if_noexcept
. Are standard library implementations typically checked at compile time to make sure exceptions are disabled, and if so, use std::move
instead std::move_if_noexcept
? Do compilers std::is_nothrow_move_constructible
emit true for all types if exceptions are disabled? Or does disabling exception support have an unexpected side effect: std:move_if_noexcept
can't enable move operations?
I am interested in what happens in practice. I understand that disabling support for exceptions takes us out of the scope of the C ++ standard.
source to share
This code outputs false true false true
on both GCC 4.9 and clang 3.5 with or without exceptions enabled:
void foo() {}
void bar() noexcept {}
void foo2() noexcept(noexcept(foo())) {}
void bar2() noexcept(noexcept(bar())) {}
int main() {
std::cout << std::boolalpha << noexcept(foo()) << ' ' << noexcept(bar())
<< ' ' << noexcept(foo2()) << ' ' << noexcept(bar2()) << std::endl;
}
So it looks like the behavior noexcept
is independent of compiler options, at least for these two compilers.
Update: VS2013 doesn't support noexcept
at all .
source to share
-fnothrow-opt Treat the throw () exception specification as if it were a noexcept specification to reduce or eliminate the text size overhead relative to a function without an exception specification. If a function has local variables of types with non-trivial destructors, the exception specification actually makes the function smaller because EH clearing for those variables can be optimized. the semantic effect is that an exception thrown from a function with such an exception specification results in a call to terminate than unexpectedly.
So according to gcc documentation, the throw functions become unnecessary.
This means that more objects will return true at least
source to share