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]

Undefined reference to std::string::_Rep::_S_empty_rep_storage when compiling with -O2.


GCC version: gcc version 3.4.0 20040128 (prerelease)
System type: i386-unknown-freebsd5.1
Configuration options: ../gcc-3.4-20040128/configure
    --disable-checking --disable-nls --enable-langauges=c,c++
    --prefix=/usr/local/gcc-3.4-20040128
    --program-suffix=-3.4-20040128
    --enable-threads --with-cpu=i686
    --enable-version-specific-runtime-libs
    --enable-libstdcxx-debug

Command line that triggers the bug: g++-3.4-20040128 -O2 string_bug.cc

Compiler output: 

    $ cat string_bug.cc
    #include <string>

    int main()
        {
            const std::string exclam= "!";
        }

    $ g++-3.4-20040128 -v -O2 --save-temps string_bug.cc
    Reading specs from /usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/specs
    Configured with: ../gcc-3.4-20040128/configure --disable-checking --disable-nls --enable-langauges=c,c++ --prefix=/usr/local/gcc-3.4-20040128 --program-suffix=-3.4-20040128 --enable-threads --with-cpu=i686 --enable-version-specific-runtime-libs --enable-libstdcxx-debug
    Thread model: posix
    gcc version 3.4.0 20040128 (prerelease)
     /usr/local/gcc-3.4-20040128/libexec/gcc/i386-unknown-freebsd5.1/3.4.0/cc1plus -E -quiet -v string_bug.cc -mtune=i686 -O2 -o string_bug.ii
    ignoring nonexistent directory "/usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/../../../../i386-unknown-freebsd5.1/include"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/include/c++
     /usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/include/c++/i386-unknown-freebsd5.1
     /usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/include/c++/backward
     /usr/local/include
     /usr/local/gcc-3.4-20040128/include
     /usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/include
     /usr/include
    End of search list.
     /usr/local/gcc-3.4-20040128/libexec/gcc/i386-unknown-freebsd5.1/3.4.0/cc1plus -fpreprocessed string_bug.ii -quiet -dumpbase string_bug.cc -mtune=i686 -auxbase string_bug -O2 -version -o string_bug.s
    GNU C++ version 3.4.0 20040128 (prerelease) (i386-unknown-freebsd5.1)
            compiled by GNU C version 3.4.0 20040128 (prerelease).
    GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64713
     as -o string_bug.o string_bug.s
     /usr/local/gcc-3.4-20040128/libexec/gcc/i386-unknown-freebsd5.1/3.4.0/collect2 -V -dynamic-linker /usr/libexec/ld-elf.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/crtbegin.o -L/usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0 -L/usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/../../.. string_bug.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/gcc-3.4-20040128/lib/gcc/i386-unknown-freebsd5.1/3.4.0/crtend.o /usr/lib/crtn.o
    string_bug.o: In function `main':
    string_bug.o(.text+0x35): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage'
    GNU ld version 2.13.2 [FreeBSD] 2002-11-27
      Supported emulations:
       elf_i386_fbsd
    collect2: ld returned 1 exit status
    $

Here's the error line, repeated for clarity:

  undefined reference to
  `std::basic_string
    <
      char, std::char_traits<char>, std::allocator<char>
    >::_Rep::_S_empty_rep_storage'

The work-around for this bug is to compile with -fno-inline; that is:

    $ g++-3.4-20040128 -O2 -fno-inline string_bug.cc

    reports no errors.

Because of the #include<string>, I need to attach a large (362K, 38K
    bzip2'd) preprocessed file. I could not figure out how to do this
    in the bugzilla interface. The best think I could think of was to
    email this message to gcc-bugs, wait for it appear in the web
    archive, and put a link to it in the bugzilla report.

Attachment: string_bug.ii.bz2
Description: Preprocessor output, bzip2'd


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