I'm seeing the following error:

In function ‘int main()’:
cc1plus: warning: dereferencing pointer ‘<anonymous>’ does break
strict-aliasing
rules
/usr/lib/gcc/i386-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_tree.h:184:
note: initialized from here

I'm unsure of these are legitimate warnings i.e. if stl_tree.h is genuinely
faulty or if it's a false positive from g++. This appears to be similar to
issue 39207.

This problem was originally encountered in chromium (dev.chromium.org) but I
have produced a much reduced test case below. I'm not expecting the reduced
test case to run of course but compilation would be nice :)

Compile with -O2 -Wall

[begin main.cc]

#include <list>
#include <map>

class MyClass {
 public:
  typedef std::list<int> MyList;
  typedef std::map<int, MyList::iterator> MyMap;

  MyClass() {}
  ~MyClass() {}

  void Fail(const int key) {
    MyMap::iterator map_iter = map_.find(key);
    // this doesn't fail
    MyList::iterator list_iter = map_iter->second;
    // this does
    list_.erase(map_iter->second);
  }

  MyList list_;
  MyMap map_;
};


int main(void)
{
  MyClass myclass;

  myclass.Fail(5);

  return 0;
}

[end main.cc]

Please let me know if you need a save-temps version too.

Thank you!

$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran --disable-libgcj
--with-tune=generic --with-arch=i586 --build=i386-redhat-linux
Thread model: posix
gcc version 4.4.0 20090310 (Red Hat 4.4.0-0.24) (GCC)


-- 
           Summary: Aliasing errors in stl_tree.h
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: craig dot schlenter at gmail dot com


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

Reply via email to