This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9666: Arg conversion problem with operator new
- From: BrainChild at Skyler dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 11 Feb 2003 20:44:31 -0000
- Subject: c++/9666: Arg conversion problem with operator new
- Reply-to: BrainChild at Skyler dot com
>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: