From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bill C Riemers To: gcc-help@gcc.gnu.org Subject: Compiling legacy code... Is this a bug??? Date: Sat, 01 Apr 2000 00:00:00 -0000 Message-ID: <38A38583.C981E206@feynman.com> X-SW-Source: 2000-q1/msg00235.html Message-ID: <20000401000000.Zj4W3ImZVZTYLBJUvnbbSO9EDl3yUqyVnMgwWW6PYbA@z> I really doubt what I'm seeing is a bug, because it is far too obvious not to have been noticed. But I can't believe the C++ standard allows this either. Consistently when I compile legacy code I'm given the following type of warning: doc2tex.l:480: warning: for conversion from `McString' to `const char *' doc2tex.l:480: warning: because conversion sequence for the argument is better doc2tex.l:482: warning: choosing `McDArray::operator char *()' over `McDArray::operator const char *() const This makes absolutely no sense to me, as it almost always results in a memory leak. Since the typical usage is: const char message[]="This is a constant string"; const char *foo() { return message; } char *foo() { char *ptr=new char [sizeof(message)]; strcpy(ptr,message); return message; } printf("The original message is '%s'\n",(const char *)foo()); char *bar=foo(); for(char *ptr=bar;*ptr;*ptr=toupper(*ptr)); printf("The new message is '%s'\n",ptr); delete [] bar; As you can see, if the wrong type of pointer is used for the first call of foo(), then there is a memory leak. I have absolutely no problem avoiding this type of problem in code I write, since I would not use the same name for both functions, and I never define both a constant and non-constant version of the same operator. However, I am lost to confuse as to how I'm suppose to compile other people's code written for older versions of g++, or other C++ compilers that don't do this type of thing. Bill The