public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Compiling legacy code... Is this a bug???
@ 2000-02-10 19:44 Bill C Riemers
  2000-04-01  0:00 ` Bill C Riemers
  0 siblings, 1 reply; 2+ messages in thread
From: Bill C Riemers @ 2000-02-10 19:44 UTC (permalink / raw)
  To: gcc-help

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<char>::operator char *()' over `McDArray<char>::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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Compiling legacy code... Is this a bug???
  2000-02-10 19:44 Compiling legacy code... Is this a bug??? Bill C Riemers
@ 2000-04-01  0:00 ` Bill C Riemers
  0 siblings, 0 replies; 2+ messages in thread
From: Bill C Riemers @ 2000-04-01  0:00 UTC (permalink / raw)
  To: gcc-help

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<char>::operator char *()' over `McDArray<char>::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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-04-01  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-10 19:44 Compiling legacy code... Is this a bug??? Bill C Riemers
2000-04-01  0:00 ` Bill C Riemers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).