[Bug libstdc++/87431] valueless_by_exception() should unconditionally return false if all the constructors are noexcept

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Sep 25 10:44:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87431

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Can we do any better than this?

--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -439,6 +439,8 @@ namespace __variant
       constexpr bool
       _M_valid() const noexcept
       {
+       if constexpr ((is_scalar_v<_Types> && ...))
+         return true;
        return this->_M_index != __index_type(variant_npos);
       }


Any non-scalar type can have a constructor that throws, which could be called
via variant::emplace.


More information about the Gcc-bugs mailing list