Re: [Boost-bugs] [Boost C++ Libraries] #12183: GCC 6.1 thinks boost::container::string violates strict aliasing

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12183: GCC 6.1 thinks boost::container::string violates strict aliasing
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-05-13 20:54:21


#12183: GCC 6.1 thinks boost::container::string violates strict aliasing
-------------------------------+------------------------
  Reporter: tavianator@… | Owner: igaztanaga
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: container
   Version: Boost 1.61.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+------------------------

Comment (by igaztanaga):

 The access to the non-active union member was intentional as all compilers
 support it (as the C standard guarantees implementation-defined behaviour,
 C++ compilers agree to support this as an extension). The same trick is
 used in libc++.

 In any case, would this "is_short" implementation avoid UB?

 {{{
    bool is_short() const
    {
       short_header hdr;
       *(unsigned char*)&hdr = *(unsigned char*)&this->members_.m_repr;
       return hdr.is_short != 0;
    }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12183#comment:2>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC