https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65085
Bug ID: 65085 Summary: Move-assigned empty string corrupt with -D_GLIBCXX_USE_CXX11_ABI=1 Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: steveire at gmail dot com GCC 5.0 generates corrupt CMake binaries currently: http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/12392/focus=12420 The cause seems to be between the new ABI and moving an empty std::string: stephen@hal:~/dev/src/playground/cpp{master}$ /home/stephen/dev/prefix/bin/g++-5.0 -v -std=gnu++11 membug.cpp -D_GLIBCXX_USE_CXX11_ABI=1 -g Using built-in specs. COLLECT_GCC=/home/stephen/dev/prefix/bin/g++-5.0 COLLECT_LTO_WRAPPER=/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../../../src/gcc/configure --prefix=/home/stephen/dev/prefix --enable-languages=c,c++ --program-suffix=-5.0 --enable-checking=release --with-system-zlib Thread model: posix gcc version 5.0.0 20150130 (experimental) (GCC) COLLECT_GCC_OPTIONS='-v' '-std=gnu++11' '-D' '_GLIBCXX_USE_CXX11_ABI=1' '-g' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D _GLIBCXX_USE_CXX11_ABI=1 membug.cpp -quiet -dumpbase membug.cpp -mtune=generic -march=x86-64 -auxbase membug -g -std=gnu++11 -version -o /tmp/ccruY1vz.s GNU C++11 (GCC) version 5.0.0 20150130 (experimental) (x86_64-unknown-linux-gnu) compiled by GNU C version 5.0.0 20150130 (experimental), GMP version 6.0.0, MPFR version 3.1.2-p3, MPC version 1.0.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../../x86_64-unknown-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../include/c++/5.0.0 /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../include/c++/5.0.0/x86_64-unknown-linux-gnu /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../include/c++/5.0.0/backward /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/include /usr/local/include /home/stephen/dev/prefix/include /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list. GNU C++11 (GCC) version 5.0.0 20150130 (experimental) (x86_64-unknown-linux-gnu) compiled by GNU C version 5.0.0 20150130 (experimental), GMP version 6.0.0, MPFR version 3.1.2-p3, MPC version 1.0.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 017a5c35f0da909f1ce909a8ebb21479 COLLECT_GCC_OPTIONS='-v' '-std=gnu++11' '-D' '_GLIBCXX_USE_CXX11_ABI=1' '-g' '-shared-libgcc' '-mtune=generic' '-march=x86-64' as -v --64 -o /tmp/ccA64A8Z.o /tmp/ccruY1vz.s GNU assembler version 2.24.51 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.24.90.20141014 COMPILER_PATH=/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/:/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/:/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/ LIBRARY_PATH=/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../x86_64-linux-gnu/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-std=gnu++11' '-D' '_GLIBCXX_USE_CXX11_ABI=1' '-g' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/collect2 -plugin /home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/liblto_plugin.so -plugin-opt=/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper -plugin-opt=-fresolution=/tmp/cckIzEMq.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/crtbegin.o -L/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0 -L/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../x86_64-linux-gnu -L/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../.. /tmp/ccA64A8Z.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o stephen@hal:~/dev/src/playground/cpp{master}$ valgrind ./a.out ==22091== Memcheck, a memory error detector ==22091== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==22091== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info ==22091== Command: ./a.out ==22091== ==22091== Conditional jump or move depends on uninitialised value(s) ==22091== at 0x4C2E129: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==22091== by 0x4F3DB08: length (char_traits.h:263) ==22091== by 0x4F3DB08: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (ostream:562) ==22091== by 0x400CA2: main (membug.cpp:10) ==22091== ==22091== Conditional jump or move depends on uninitialised value(s) ==22091== at 0x4C2E138: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==22091== by 0x4F3DB08: length (char_traits.h:263) ==22091== by 0x4F3DB08: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (ostream:562) ==22091== by 0x400CA2: main (membug.cpp:10) ==22091== ==22091== Conditional jump or move depends on uninitialised value(s) ==22091== at 0x5746271: _IO_file_overflow@@GLIBC_2.2.5 (fileops.c:859) ==22091== by 0x574718B: _IO_default_xsputn (genops.c:480) ==22091== by 0x5745161: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1345) ==22091== by 0x573AB6C: fwrite (iofwrite.c:43) ==22091== by 0x4F3D80D: sputn (streambuf:451) ==22091== by 0x4F3D80D: __ostream_write<char, std::char_traits<char> > (ostream_insert.h:50) ==22091== by 0x4F3D80D: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) (ostream_insert.h:101) ==22091== by 0x4F3DB16: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (ostream:561) ==22091== by 0x400CA2: main (membug.cpp:10) ==22091== ==22091== Conditional jump or move depends on uninitialised value(s) ==22091== at 0x574629E: _IO_file_overflow@@GLIBC_2.2.5 (fileops.c:867) ==22091== by 0x574718B: _IO_default_xsputn (genops.c:480) ==22091== by 0x5745161: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1345) ==22091== by 0x573AB6C: fwrite (iofwrite.c:43) ==22091== by 0x4F3D80D: sputn (streambuf:451) ==22091== by 0x4F3D80D: __ostream_write<char, std::char_traits<char> > (ostream_insert.h:50) ==22091== by 0x4F3D80D: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) (ostream_insert.h:101) ==22091== by 0x4F3DB16: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (ostream:561) ==22091== by 0x400CA2: main (membug.cpp:10) ==22091== ==22091== Conditional jump or move depends on uninitialised value(s) ==22091== at 0x574718F: _IO_default_xsputn (genops.c:480) ==22091== by 0x5745161: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1345) ==22091== by 0x573AB6C: fwrite (iofwrite.c:43) ==22091== by 0x4F3D80D: sputn (streambuf:451) ==22091== by 0x4F3D80D: __ostream_write<char, std::char_traits<char> > (ostream_insert.h:50) ==22091== by 0x4F3D80D: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) (ostream_insert.h:101) ==22091== by 0x4F3DB16: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (ostream:561) ==22091== by 0x400CA2: main (membug.cpp:10) ==22091== ==22091== Syscall param write(buf) points to uninitialised byte(s) ==22091== at 0x57B7130: __write_nocancel (syscall-template.S:81) ==22091== by 0x5744A82: _IO_file_write@@GLIBC_2.2.5 (fileops.c:1253) ==22091== by 0x5745F5B: new_do_write (fileops.c:530) ==22091== by 0x5745F5B: _IO_do_write@@GLIBC_2.2.5 (fileops.c:503) ==22091== by 0x5746332: _IO_file_overflow@@GLIBC_2.2.5 (fileops.c:868) ==22091== by 0x57427E8: putc (putc.c:31) ==22091== by 0x4F3D29C: sputc (streambuf:434) ==22091== by 0x4F3D29C: std::ostream::put(char) (ostream.tcc:163) ==22091== by 0x4F3D4CE: std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&) (ostream:591) ==22091== by 0x400CAF: main (membug.cpp:10) ==22091== Address 0x4026000 is not stack'd, malloc'd or (recently) free'd ==22091== ==22091== ==22091== HEAP SUMMARY: ==22091== in use at exit: 72,704 bytes in 1 blocks ==22091== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated ==22091== ==22091== LEAK SUMMARY: ==22091== definitely lost: 0 bytes in 0 blocks ==22091== indirectly lost: 0 bytes in 0 blocks ==22091== possibly lost: 0 bytes in 0 blocks ==22091== still reachable: 72,704 bytes in 1 blocks ==22091== suppressed: 0 bytes in 0 blocks ==22091== Rerun with --leak-check=full to see details of leaked memory ==22091== ==22091== For counts of detected and suppressed errors, rerun with: -v ==22091== Use --track-origins=yes to see where uninitialised values come from ==22091== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 1 from 1) stephen@hal:~/dev/src/playground/cpp{master}$ /home/stephen/dev/prefix/bin/g++-5.0 -v -std=gnu++11 membug.cpp -D_GLIBCXX_USE_CXX11_ABI=0 -g Using built-in specs. COLLECT_GCC=/home/stephen/dev/prefix/bin/g++-5.0 COLLECT_LTO_WRAPPER=/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../../../src/gcc/configure --prefix=/home/stephen/dev/prefix --enable-languages=c,c++ --program-suffix=-5.0 --enable-checking=release --with-system-zlib Thread model: posix gcc version 5.0.0 20150130 (experimental) (GCC) COLLECT_GCC_OPTIONS='-v' '-std=gnu++11' '-D' '_GLIBCXX_USE_CXX11_ABI=0' '-g' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D _GLIBCXX_USE_CXX11_ABI=0 membug.cpp -quiet -dumpbase membug.cpp -mtune=generic -march=x86-64 -auxbase membug -g -std=gnu++11 -version -o /tmp/ccyzxV7A.s GNU C++11 (GCC) version 5.0.0 20150130 (experimental) (x86_64-unknown-linux-gnu) compiled by GNU C version 5.0.0 20150130 (experimental), GMP version 6.0.0, MPFR version 3.1.2-p3, MPC version 1.0.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../../x86_64-unknown-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../include/c++/5.0.0 /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../include/c++/5.0.0/x86_64-unknown-linux-gnu /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../include/c++/5.0.0/backward /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/include /usr/local/include /home/stephen/dev/prefix/include /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list. GNU C++11 (GCC) version 5.0.0 20150130 (experimental) (x86_64-unknown-linux-gnu) compiled by GNU C version 5.0.0 20150130 (experimental), GMP version 6.0.0, MPFR version 3.1.2-p3, MPC version 1.0.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 017a5c35f0da909f1ce909a8ebb21479 COLLECT_GCC_OPTIONS='-v' '-std=gnu++11' '-D' '_GLIBCXX_USE_CXX11_ABI=0' '-g' '-shared-libgcc' '-mtune=generic' '-march=x86-64' as -v --64 -o /tmp/cc2PCe0h.o /tmp/ccyzxV7A.s GNU assembler version 2.24.51 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.24.90.20141014 COMPILER_PATH=/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/:/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/:/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/ LIBRARY_PATH=/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../x86_64-linux-gnu/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-std=gnu++11' '-D' '_GLIBCXX_USE_CXX11_ABI=0' '-g' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/collect2 -plugin /home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/liblto_plugin.so -plugin-opt=/home/stephen/dev/prefix/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper -plugin-opt=-fresolution=/tmp/cc4L6STY.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/crtbegin.o -L/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0 -L/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../x86_64-linux-gnu -L/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/../../.. /tmp/cc2PCe0h.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /home/stephen/dev/prefix/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o stephen@hal:~/dev/src/playground/cpp{master}$ valgrind ./a.out ==22107== Memcheck, a memory error detector ==22107== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==22107== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info ==22107== Command: ./a.out ==22107== ==22107== ==22107== HEAP SUMMARY: ==22107== in use at exit: 72,704 bytes in 1 blocks ==22107== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated ==22107== ==22107== LEAK SUMMARY: ==22107== definitely lost: 0 bytes in 0 blocks ==22107== indirectly lost: 0 bytes in 0 blocks ==22107== possibly lost: 0 bytes in 0 blocks ==22107== still reachable: 72,704 bytes in 1 blocks ==22107== suppressed: 0 bytes in 0 blocks ==22107== Rerun with --leak-check=full to see details of leaked memory ==22107== ==22107== For counts of detected and suppressed errors, rerun with: -v ==22107== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1 from 1) stephen@hal:~/dev/src/playground/cpp{master}$ cat membug.cpp #include <cstdio> #include <iostream> #include <vector> #include <string> int main() { std::string s(""); std::string m = std::move(s); std::cout << m.c_str() << std::endl; return 0; }