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

            Bug ID: 87431
           Summary: valueless_by_exception() should unconditionally return
                    false if all the constructors are noexcept
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

Right now the variant::valueless_by_exception() calls !_M_valid() that is
defined like that:

      _M_valid() const noexcept
      {
        return this->_M_index != __index_type(variant_npos);
      }

Above code is quite complex for the optimizer. It may be profitable to detect
variant types that never have valueless_by_exception() state and re-implement
_M_valid:


      _M_valid() const noexcept
      {
        return __always_valid::value /*compile-time constant*/ ||
this->_M_index != __index_type(variant_npos);
      }

Such change would improve assembly for multiple functions including
comparisons, swap, get, constructors.

Reply via email to