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
+7 -1
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)
{