With gcc-4.4.2 the following code generates warnings about strict aliasing:

=====| bug.cpp |===================================
#include <set>
#ifdef SHOW_BUG
struct foo {
    int i;
    bool operator<(foo const &o) const { return i < o.i; }
};
#else
typedef int foo;
#endif
int main() { std::set<foo>().insert((foo) {0}); }
=====| bug.cpp |===================================

$ gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.4.2-src/configure --prefix=/home/rjo/apps/gcc-4.4.2
--with-gmp=/home/rjo/apps --with-mpfr=/home/rjo/apps --disable-nls
--disable-multilib
Thread model: posix
gcc version 4.4.2 (GCC)

$ gcc -Wall -O3 -DSHOW_BUG bug.cpp
bug.cpp: In function 'int main()':
bug.cpp:5: warning: dereferencing pointer '__x.15' does break strict-aliasing
rules
/home/rjo/apps/gcc-4.4.2/lib/gcc/x86_64-unknown-linux-gnu/4.4.2/../../../../include/c++/4.4.2/bits/stl_tree.h:525:
note: initialized from here
/home/rjo/experiments/scratch.cpp:5: warning: dereferencing pointer '__x.15'
does break strict-aliasing rules
/home/rjo/apps/gcc-4.4.2/lib/gcc/x86_64-unknown-linux-gnu/4.4.2/../../../../include/c++/4.4.2/bits/stl_tree.h:525:
note: initialized from here

In addition to the problem of the STL (appearing to?) break strict-aliasing
rules, it looks like bug #38477 is back

Below is the (hopefully) relevant snippet of CFG. It looks exactly like the
issue described in bug #38477, with static cast voodoo:

static const _Val& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare,
_Alloc>::_S_value(const std::_Rb_tree_node_base*) [with _Key = foo, _Val = foo,
_KeyOfValue = std::_Identity<foo>, _Compare = std::less<foo>, _All
oc = std::allocator<foo>] (const struct _Rb_tree_node_base * __x)
{
  const struct _Rb_tree_node * __x.15;
  const struct foo & D.8747;

<bb 2>:
  __x.15 = (const struct _Rb_tree_node *) __x;
  D.8747 = &__x.15->_M_value_field;
  return D.8747;

}

Also, is there a particular reason the diagnostic says "does break" instead of
"breaks" ? The former may be technically correct English but sounds strange,
even if there's a corresponding "may break" diagnostic.


-- 
           Summary: std::set: dereferencing pointer '__x.15' does break
                    strict-aliasing rules
           Product: gcc
           Version: 4.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: scovich at gmail dot com
  GCC host triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42077

Reply via email to