public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: BrainChild@Skyler.com
To: gcc-gnats@gcc.gnu.org
Subject: c++/9666: Arg conversion problem with operator new
Date: Tue, 11 Feb 2003 20:46:00 -0000	[thread overview]
Message-ID: <20030211204431.30598.qmail@sources.redhat.com> (raw)


>Number:         9666
>Category:       c++
>Synopsis:       Arg conversion problem with operator new
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 11 20:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Don Stauffer
>Release:        3.2
>Organization:
>Environment:
Cygwin under Windows 2000 Professional
>Description:
g++ produces error "size in array new must have integral type" if you use new[] with an argument of a class with two integral conversion operators which are identical exception one is a const method.  The conversion works if used to pass the class object as a size_t function argument, and works with new if you remove either one of the conversion operators.
>How-To-Repeat:
#include	<cstddef>

struct	X
{
	operator size_t	()				{	return
2;	}
	operator size_t	()	const	{	return	3;	}
};

char	*f1	(	size_t	n	)		{	return
new	char[n];	}

char	*f2	(	const X	&x	)	{	return	new
char[x];	}

int	main	(void)					{	}

/*

$ g t.cpp -ot
t.cpp: In function `char* f2(const X&)':
t.cpp:11: size in array new must have integral type

*/
>Fix:
Workaround: Call a function which converts the argument and allocates the memory rather than calling new directly.
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2003-02-11 20:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-11 20:46 BrainChild [this message]
2003-02-14 21:22 bangerth

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=20030211204431.30598.qmail@sources.redhat.com \
    --to=brainchild@skyler.com \
    --cc=gcc-gnats@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).