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]

string -> char* conversion problem?


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


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