This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
string -> char* conversion problem?
- To: egcs-bugs at cygnus dot com
- Subject: string -> char* conversion problem?
- From: "William S. Lear" <rael at zopyra dot com>
- Date: Tue, 8 Dec 1998 01:27:00 -0600 (CST)
I checked the FAQ and saw no mention of what appears to be a problem:
% g++ -v
Reading specs from /opt/egcs-1.1b/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
% cat t.cc
#include <string>
#include <iostream.h>
main() {
const string self("X");
const char* xy = (self + string(".Y")).c_str();
const char* xz = (self + string(".Z")).c_str();
cout << "X.Y = " << xy << endl;
cout << "X.Z = " << xz << endl;
}
% g++ -pipe -Wall t.cc
% ./a.out
X.Y = X.Z
X.Z = X.Z
I can understand how this would happen (first temp string getting
blotted out), but should there not be some sort of warning? Is this
behavior standard?
Thanks.
Bill