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

Subject: [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-08 20:41:58


#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
 Keywords: |
------------------------------+------------------------
 The following simple test case aborts when built with -O2, but works fine
 with -fno-strict-aliasing.

 {{{
 $ cat foo.cpp
 #include <boost/container/string.hpp>
 #include <cstdlib>
 #include <utility>

 using boost::container::string;

 struct foo
 {
   __attribute__((noinline))
   foo(string str)
     : m_str{std::move(str)},
       m_len{m_str.length()}
   { }

   string m_str;
   std::size_t m_len;
 };

 int main() {
   foo f{"the quick brown fox jumps over the lazy dog"};
   if (f.m_len == 0) {
     std::abort();
   }
   return 0;
 }
 $ g++ -O2 -Wall foo.cpp -o foo && ./foo
 [1] 6375 abort (core dumped) ./foo
 }}}

 I reported this as [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71002 GCC
 bug 71002] but I'm not sure that the code is actually correct. It seems
 to at least access a non-active union member (the is_short bitfield).
 There may be other aliasing issues with the union -- in some cases it
 seems GCC wants you to access the members through the union directly, not
 through a pointer to a union member; see
 [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14319 GCC bug 14319] for
 example.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12183>
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