This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/42032] Aliasing errors in stl_tree.h
- From: "craig dot schlenter at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Nov 2009 04:37:57 -0000
- Subject: [Bug c++/42032] Aliasing errors in stl_tree.h
- References: <bug-42032-18432@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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 <map>
>
> int main(void)
> {
> typedef std::map<int, char*> 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 '<anonymous>' 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 <map>
#include <string>
int main(void)
{
typedef std::map<std::string, char*> 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