This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

Re: delete[] works on static arrays


Jason Merrill <jason@cygnus.com> writes:

> I'm not sure about that.  The draft says

>             The operand shall have a pointer type, or a class type having
>   a single conversion function (_class.conv.fct_)  to  a  pointer  type.

> but it also says, about array references, that

>   One of the expressions shall have the type "pointer to T"

> so I think that the pointer can be the result of the default
> array-to-pointer conversion.

Perhaps we should ask in comp.std.c++?  Or is there anyone from the
committee reading this? :-)

> If so, this code is well-formed, and the current error message for
> 'delete' is wrong.

The only valid usage of delete I can think of that involves actual
array types is like this:

void foo(int (&a)[3]) { delete[] a; }

Deleting a variable declared as an array is never correct, therefore I
believe the committee has really meant a pointer type in this case.
WRT arrays, the standard explicitly mentions array-to-pointer decaying 
in dcl.array.

> I would suggest moving the check to before the switch, making it a
> warning, and adding a call to build_expr_type_conversion.

That's fine for me, but it is currently beyond my knowledge of gcc.
I'm pretty sure this must be straighforward to do, but I'd have to
spend some time finding out how to do that, and I've got a MSc thesis
to get finished in one week.  So I'll leave this for someone else to
do, unless you can wait :-)

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil



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