ios_base.h:96:24: runtime error: load of value 4294967221which is not a valid value for type 'std::_Ios_Fmtflags'

I know this has been discussed before:

    ios_base.h:96:24: runtime error: load of value 4294967221, which
is not a valid value for type 'std::_Ios_Fmtflags'

and

    ios_base.h:80:67: runtime error: load of value 4294967221, which
is not a valid value for type 'std::_Ios_Fmtflags'

Line 96 offender is the return:

      inline _Ios_Fmtflags&
      operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
      { return __a = __a & __b; }

Line 80 offender is the return:

      inline _Ios_Fmtflags
      operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
      { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); }

For example, http://lists.cs.uiuc.edu/pipermail/llvmbugs/2013-December/031638.html,
http://llvm.org/bugs/show_bug.cgi?id=18156 and
https://www.marshut.net/suwhu/undefined-behavior-sanitizing-with-clang.html.
But I can't seem to find the solution (only hits on the problem).

Clang has been tagging it for a couple of years now. I'd like to clear
the error on my MacBook (OS X 10.8.5, fully patched).

What is the resolution?

Thanks in advance.

I know this has been discussed before:

    ios_base.h:96:24: runtime error: load of value 4294967221, which
is not a valid value for type 'std::_Ios_Fmtflags'

and

    ios_base.h:80:67: runtime error: load of value 4294967221, which
is not a valid value for type 'std::_Ios_Fmtflags'

Line 96 offender is the return:

      inline _Ios_Fmtflags&
      operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
      { return __a = __a & __b; }

Line 80 offender is the return:

      inline _Ios_Fmtflags
      operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
      { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); }

Past discussions include, for example,
http://lists.cs.uiuc.edu/pipermail/llvmbugs/2013-December/031638.html,
http://llvm.org/bugs/show_bug.cgi?id=18156 and
https://www.marshut.net/suwhu/undefined-behavior-sanitizing-with-clang.html.
But I can't seem to find the solution (only hits on the problem).

Clang has been tagging it for a couple of years now. I'd like to clear
the error on my MacBook (OS X 10.8.5, fully patched).

What is the resolution?

Thanks in advance.

I know this has been discussed before:

    ios_base.h:96:24: runtime error: load of value 4294967221, which
is not a valid value for type 'std::_Ios_Fmtflags'

and

    ios_base.h:80:67: runtime error: load of value 4294967221, which
is not a valid value for type 'std::_Ios_Fmtflags'

Line 96 offender is the return:

      inline _Ios_Fmtflags&
      operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
      { return __a = __a & __b; }

Line 80 offender is the return:

      inline _Ios_Fmtflags
      operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
      { return _Ios_Fmtflags(static_cast<int>(__a) &
static_cast<int>(__b)); }

For example,
http://lists.cs.uiuc.edu/pipermail/llvmbugs/2013-December/031638.html,
http://llvm.org/bugs/show_bug.cgi?id=18156 and
https://www.marshut.net/suwhu/undefined-behavior-sanitizing-with-clang.html
.
But I can't seem to find the solution (only hits on the problem).

Clang has been tagging it for a couple of years now. I'd like to clear
the error on my MacBook (OS X 10.8.5, fully patched).

What is the resolution?

The problem is in the definition of operator~:

  inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
  operator~(_Ios_Fmtflags __a)
  { return _Ios_Fmtflags(~static_cast<int>(__a)); }

Try changing that to

  inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
  operator~(_Ios_Fmtflags __a)
  { return __a ^ _Ios_Fmtflags(static_cast<int>(_S_ios_fmtflags_end) - 1); }

You could alternatively set up a suppression for this ubsan message (and be
careful not to build with -fstrict-enums); see
http://clang.llvm.org/docs/SanitizerSpecialCaseList.html.

Thanks in advance.

Thanks Richard.

And sorry about the CFE-Dev mailing. It was intended for CFE-Users. I
was not paying enough attention to autocomplete.

Jeff