Fixes Trac #12183 (GCC 6.1 thinks boost::container::string violates strict aliasing)

This commit is contained in:
Ion Gaztañaga
2016-05-16 16:59:25 +02:00
parent 132e57a348
commit b888d2ae47
2 changed files with 8 additions and 2 deletions

View File

@@ -1218,10 +1218,10 @@ use [*Boost.Container]? There are several reasons for that:
* Fixed bugs:
* [@https://svn.boost.org/trac/boost/ticket/11170 Trac #11170: ['"Doc slip for index_of"]].
* [@https://svn.boost.org/trac/boost/ticket/12177 Trac #12177: ['"vector::priv_merge uses unqualified uintptr_t"]].
* [@https://svn.boost.org/trac/boost/ticket/12183 Trac #12183: ['"GCC 6.1 thinks boost::container::string violates strict aliasing"]].
[endsect]
[section:release_notes_boost_1_61_00 Boost 1.61 Release]
* [classref boost::container::small_vector] supports more constructors and assignments.

View File

@@ -230,7 +230,13 @@ class basic_string_base
protected:
bool is_short() const
{ return static_cast<bool>(this->members_.m_repr.s.h.is_short != 0); }
{
//Access and copy (to avoid UB) the first byte of the union to know if the
//active representation is short or long
short_header hdr;
*(unsigned char*)&hdr = *(unsigned char*)&this->members_.m_repr;
return hdr.is_short != 0;
}
void is_short(bool yes)
{