This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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 '<anonymous>' 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 <map>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]