[Bug c++/42032] New: Aliasing errors in stl_tree.h

2009-11-13 Thread craig dot schlenter at gmail dot com
I'm seeing the following error:

In function ‘int main()’:
cc1plus: warning: dereferencing pointer ‘’ 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 
#include 

class MyClass {
 public:
  typedef std::list MyList;
  typedef std::map 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



[Bug c++/42032] Aliasing errors in stl_tree.h

2009-11-13 Thread craig dot schlenter at gmail dot com


--- Comment #2 from craig dot schlenter at gmail dot com  2009-11-13 19:34 
---
(In reply to comment #1)
> Might be related to PR 39390.

Would it be possible for someone to test the code from the description section
with trunk please .. if error messages were removed, the problem should be gone
:) I unfortunately don't have easy access to a more modern gcc than 4.4.0 to
test with.

Thank you.


-- 


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



[Bug c++/42032] Aliasing errors in stl_tree.h

2009-11-15 Thread craig dot schlenter at gmail dot com


--- Comment #7 from craig dot schlenter at gmail dot com  2009-11-16 04:37 
---
(In reply to comment #3)
> I brought this up on the Google-internal C list.  They reduced it further:
> 
> $ cat main.cc
> #include 
> 
> int main(void)
> {
>typedef std::map MyMap2;
>MyMap2 map2_;
>MyMap2::iterator map_iter2 = map2_.find(5);
>return *map_iter2->second;
> }
> $ g++ -O3 -Wall -c main.cc
> main.cc: In function 'int main()':
> main.cc:8: warning: dereferencing pointer '' does break
> strict-aliasing rules
> /opt/local/include/gcc44/c++/bits/stl_tree.h:179: note: initialized from here

Hironori Bono spotted btw. that if the key for the map is changed from an int
to a std::string, then the aliasing warning disappears:

#include 
#include 

int main(void)
{
  typedef std::map MyMap2;
  MyMap2 map2_;
  MyMap2::iterator map_iter2 = map2_.find("hello");
  return *map_iter2->second;
}

This is rather strange and confusing.


-- 


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