Fix for PR libstdc++/51142 causes incompatibility when mixing C++98 and C++11 code with gcc-4.6.3 and later

Nicolas Roeser nicolas.roeser@uni-ulm.de
Mon Sep 17 07:38:00 GMT 2012


Hello!

We found that the fix for PR 51142
<URL:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51142>, which was
checked in in SVN r181427
<URL:http://gcc.gnu.org/viewcvs?view=revision&revision=181394>, causes
code to break when different C++ versions are used.

A minimal example is attached. It results in a segfault. Cause is that
the wrong erase function is called:
#11 0x0804894d in std::multimap<int, int, std::less<int>,
std::allocator<std::pair<int const, int> > >::erase (this=0x804d288,
__position=...) at /usr/include/c++/4.6/bits/stl_multimap.h:540
#12 0x080490c3 in Old_Map::RemoveElements (this=0xffffcbf8) at old.cc:14
#13 0x08049492 in main () at main.cc:10

The two erase functions have the same parameters, but different return
value (void vs. iterator).

When optimizations are enabled or on 64-bit architectures, return values
are handled differently, so the problem does not necessarily appear.

Is linking together several object files compiled with different C++
versions not supported?

Thanks
-- 
Nico
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cc
Type: text/x-c++src
Size: 180 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20120917/549b4ae9/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: new.cc
Type: text/x-c++src
Size: 273 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20120917/549b4ae9/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: new.h
Type: text/x-chdr
Size: 177 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20120917/549b4ae9/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: old.cc
Type: text/x-c++src
Size: 273 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20120917/549b4ae9/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: old.h
Type: text/x-chdr
Size: 178 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20120917/549b4ae9/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: build.sh
Type: application/x-sh
Size: 391 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20120917/549b4ae9/attachment.sh>


More information about the Libstdc++ mailing list