public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bill C Riemers <bcr@feynman.com>
To: gcc-help@gcc.gnu.org
Subject: Compiling legacy code... Is this a bug???
Date: Thu, 10 Feb 2000 19:44:00 -0000	[thread overview]
Message-ID: <38A38583.C981E206@feynman.com> (raw)

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

WARNING: multiple messages have this Message-ID
From: Bill C Riemers <bcr@feynman.com>
To: gcc-help@gcc.gnu.org
Subject: Compiling legacy code... Is this a bug???
Date: Sat, 01 Apr 2000 00:00:00 -0000	[thread overview]
Message-ID: <38A38583.C981E206@feynman.com> (raw)
Message-ID: <20000401000000.Zj4W3ImZVZTYLBJUvnbbSO9EDl3yUqyVnMgwWW6PYbA@z> (raw)

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

             reply	other threads:[~2000-02-10 19:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-10 19:44 Bill C Riemers [this message]
2000-04-01  0:00 ` Bill C Riemers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38A38583.C981E206@feynman.com \
    --to=bcr@feynman.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).