public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/62186] New: segfault on map.insert
@ 2014-08-19 12:10 james1479 at gmail dot com
  2014-08-19 16:17 ` [Bug c++/62186] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: james1479 at gmail dot com @ 2014-08-19 12:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62186

            Bug ID: 62186
           Summary: segfault on map.insert
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: james1479 at gmail dot com

Getting a segfault on map.insert if called as a global initialiser from another
source file.

#### a.cpp    ####
#include <map>

std::map<int, int> m;

int g() {
    m.insert( std::pair<int,int>(1,1) );
    return 0;
}
#### main.cpp #### 
int g(int i);
int a = g(1);

int main() { return 0; }
##################

This code either works or segfaults depending on which order they are passed to
g++:
% g++ a.cpp main.cpp
% ./a.out 
% g++ main.cpp a.cpp
% ./a.out 
[1]    9548 segmentation fault (core dumped)  ./a.out

This also happens if they are compiled to .o files and linked together:
% g++ -c a.cpp 
% g++ -c main.cpp
% g++ a.o main.o 
% ./a.out 
% g++ main.o a.o
% ./a.out
[1]    10485 segmentation fault (core dumped)  ./a.

The program works if compiled as a single source program. 

Or if `int a = g(1);` is moved inside the main function.

Or if m.clear() is called before the insert.

g++ version (from archlinux repo):
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-4.9.1/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-cloog-backend=isl --disable-isl-version-check
--disable-cloog-version-check --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu --disable-multilib
--disable-werror --enable-checking=release
Thread model: posix
gcc version 4.9.1 (GCC)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/62186] segfault on map.insert
  2014-08-19 12:10 [Bug c++/62186] New: segfault on map.insert james1479 at gmail dot com
@ 2014-08-19 16:17 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-08-19 16:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62186

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The order outside translation units of initialization is unspecified in c++.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-19 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-19 12:10 [Bug c++/62186] New: segfault on map.insert james1479 at gmail dot com
2014-08-19 16:17 ` [Bug c++/62186] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).