[Bug c++/42087] New: stl::map breaks strict-aliasing rules

2009-11-17 Thread riddikulus at verizon dot net
The attached short snippet fails to compile on GCC 4.4.1 and 4.4.2 (latest
release), due to aliasing issues in stl::map.  Ignore the logic as it has been
contorted to reduce the test code fragment size.

First bug submit, so I hope this is close to proper procedure.

==
g++ -O2 -Wall -Werror -c tst5.cxx

-*- mode: compilation; default-directory: "~/" -*-
Compilation started at Tue Nov 17 21:37:41

g++ -v -save-temps -O2 -Wall -Werror -c tst5.cxx
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.4
--enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/
--with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap
--with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.4
--enable-linux-futex --without-system-libunwind --with-arch-32=i586
--with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.4.1 [gcc-4_4-branch revision 150839] (SUSE Linux) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-Wall' '-Werror' '-c'
'-shared-libgcc' '-mtune=generic'
 /usr/lib64/gcc/x86_64-suse-linux/4.4/cc1plus -E -quiet -v -D_GNU_SOURCE
tst5.cxx -mtune=generic -Wall -Werror -O2 -fpch-preprocess -o tst5.ii
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.4
 /usr/include/c++/4.4/x86_64-suse-linux
 /usr/include/c++/4.4/backward
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/4.4/include
 /usr/lib64/gcc/x86_64-suse-linux/4.4/include-fixed
 /usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-Wall' '-Werror' '-c'
'-shared-libgcc' '-mtune=generic'
 /usr/lib64/gcc/x86_64-suse-linux/4.4/cc1plus -fpreprocessed tst5.ii -quiet
-dumpbase tst5.cxx -mtune=generic -auxbase tst5 -O2 -Wall -Werror -version -o
tst5.s
GNU C++ (SUSE Linux) version 4.4.1 [gcc-4_4-branch revision 150839]
(x86_64-suse-linux)
compiled by GNU C version 4.4.1 [gcc-4_4-branch revision 150839], GMP
version 4.3.1, MPFR version 2.4.1-p5.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9324fd3305365d6cc397a0043b4bc055
cc1plus: warnings being treated as errors
tst5.cxx: In function 'int main()':
tst5.cxx:23: error: dereferencing pointer '' does break
strict-aliasing rules
/usr/include/c++/4.4/bits/stl_tree.h:179: note: initialized from here

Compilation exited abnormally with code 1 at Tue Nov 17 21:37:41
==

SOURCE FOLLOWS:
//
//  Compile with:  g++ -O2 -Wall -Werror -c tst.cxx
//

#include 

class C
{
  typedef std::map< C *, C * > CloneList;
  static CloneList clone_list;

public:
  C() {}

  C *clone()
  {
clone_list.clear();

C  *res = 0;
CloneList::iterator ptr = clone_list.find( this );

if ( ptr != clone_list.end() )
  res = ptr -> second;
else
{
  res = new C;
  clone_list[ this ] = res;
}
return res ;
  }
} ;



int main()
{
  C *c = new C;

  return c -> clone() != 0;
}

//


-- 
   Summary: stl::map breaks strict-aliasing rules
   Product: gcc
       Version: 4.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: riddikulus at verizon dot net


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



[Bug c++/42087] stl::map breaks strict-aliasing rules

2009-11-17 Thread riddikulus at verizon dot net


--- Comment #1 from riddikulus at verizon dot net  2009-11-18 03:43 ---
Created an attachment (id=19032)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19032&action=view)
Test code


-- 


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



[Bug c++/42087] stl::map breaks strict-aliasing rules

2009-11-17 Thread riddikulus at verizon dot net


--- Comment #2 from riddikulus at verizon dot net  2009-11-18 03:44 ---
Created an attachment (id=19033)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19033&action=view)
gcc -v -save-temps output


-- 


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



[Bug c++/42087] stl::map breaks strict-aliasing rules

2009-11-18 Thread riddikulus at verizon dot net


--- Comment #4 from riddikulus at verizon dot net  2009-11-19 01:22 ---
(In reply to comment #3)
> 
> *** This bug has been marked as a duplicate of 39390 ***
> 

Just FYI, the test code in bug #39390 does not generate any warnings with GCC
4.4.1, while the test code attached to this bug (#42087) does.  This suggests
these two bugs "might" not be precisely the same one.

I'll defer to your experience though.


-- 


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