[Bug c++/42032] Aliasing errors in stl_tree.h
craig dot schlenter at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Nov 16 04:38:00 GMT 2009
------- 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
More information about the Gcc-bugs
mailing list