This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Conversion operator and new


Greetings!

g++ produces an error "size in array new must have integral type" in
function f2.  I expected the conversion operators to convert x to
size_t, which is an integral type.  They do if I remove *either* the
const *or* the non-const version of operator size_t, and they do for
passing x to function f1 in any case.

Is this a bug?

#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

*/
-- 
Don Stauffer, Office Manager
Indiana Epilepsy and Child Neurology, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]