What can you "new"

Unknown W. Brackets unknown at simplemachines.org
Tue Mar 24 13:46:58 PDT 2009


No, I agree.  I think for the sake of templating, improving the error 
message is the best option - probably #3 (special case error message) imho.

-[Unknown]


Andrei Alexandrescu wrote:
> Steve Teale wrote:
>> Unknown W. Brackets Wrote:
>>
>>> Steve,
>>>
>>> It's not exactly prose, but the error message is correct.  It says:
>>>
>>> "Error: new can only create structs, dynamic arrays or class objects, 
>>> not char[]'s."
>>>
>>> So:
>>>
>>> 1. You didn't try to allocate space for a struct (e.g. new struct_t.)
>>> 2. You didn't try to allocate space for a dynamic array (new char[5].)
>>> 3. You didn't try to allocate space for a class object (new Class.)
>>>
>>>  From your code, it's obvious what you were meaning to do, so I would 
>>> agree that changing this would be good.  Options I see are:
>>>
>>> 1. Improve the error message, e.g.: "Error: new can only create 
>>> structs, sized dynamic arrays, or class objects; char[] cannot be 
>>> created."
>>>
>>> 2. Change the compiler to react as if you used new char[0].
>>>
>>> 3. Special case the error message, e.g.: "Error: new can only create 
>>> dynamic arrays with an initial length, use 0 for empty."
>>>
>>
>> Best answer yet! You win a free holiday in Tanzania (as long as you 
>> pay to get there). Yes it would be great if the error message gave you 
>> clue about specifying the size. Then, all the magic is removed, and 
>> you know just where you are. But even then, zero would be quite a good 
>> default!
> 
> I don't mean to ruin anyone's holiday in Tanzania but zero is a crappy 
> default. When I say new char[] it's not like I'm really hoping for a 
> shortcut for new char[0]. It's more likely new char[] is really 
> originating as new T where T = char[].
> 
> Andrei



More information about the Digitalmars-d mailing list