c++/8172: no operator+ for string in library
gunneyb@llnl.gov
gunneyb@llnl.gov
Tue Oct 8 15:46:00 GMT 2002
>Number: 8172
>Category: c++
>Synopsis: undefined reference to operator+ for string
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Oct 08 15:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Brian T. N. Gunney
>Release: 3.2
>Organization:
Lawrence Livermore National Lab
>Environment:
System: Linux tux75.llnl.gov 2.4.9-31smp #1 SMP Tue Feb 26 06:55:00 EST 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.2/configure --prefix=/usr/apps/gcc/3.2
>Description:
The operator+ for string is missing when compiled with -fno-implicit-template.
The error occurs at link time as follows:
> /usr/apps/gcc/3.2/bin/g++ -o noplus noplus.o
noplus.o: In function `main':
noplus.o(.text+0xd8): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: ld returned 1 exit status
>How-To-Repeat:
Program text:
#include <string>
#include <iostream>
using namespace std;
int main() {
string s1 = "first";
string s2 = "second";
string s3, s4;
// This will not link.
s3 = s1 + s2;
// This works.
s4 = s1;
s4 += s2;
cout << "s1 = " << s1 << endl;
cout << "s2 = " << s2 << endl;
cout << "s3 = " << s3 << endl;
cout << "s4 = " << s4 << endl;
return 0;
}
Compile command:
g++ -fno-implicit-templates noplus.cc
>Fix:
Replace s3 = s1 + s2;
With s3 = s1; s3 += s3;
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list