Topic: Defect Report: deallocation function look-up and resolution for delete-expression


Author: pongba@gmail.com
Date: Mon, 27 Nov 2006 09:49:10 CST
Raw View
C++03, 12.5/4 says:

[quote]
    If a delete-expression begins with a unary :: operator, the
deallocation function's name is looked up in global scope. Otherwise,
if the delete-expression is used to deallocate a class object whose
static type has a virtual destructor, the deallocation function is the
one found by the lookup in the definition of the dynamic type's
virtual destructor (12.4).104) [...]. If this lookup fails to find the
name, the name is looked up in the global scope. *If the result of the
lookup is ambiguous or inaccessible, or if the lookup selects a
placement deallocation function, the program is ill-formed*.
[/quote]

It's not clear how the name lookup is done. Is it through overload
resolution? If it is, how is the candidate set formed? If it's not,
then does that mean only the non-placement deallocation function is
looked up or what?

In particular, whether the example below is ill-formed is left
unanswered:

struct S
{
void operator delete(void*);
void operator delete(void*, size_t);
};

S* ps = ...;
delete ps; // ambiguous?

I see that Core language Issue 255 essentially stated the same
question, but the suggested answer is still confusing:

[quote]
I think you might get the right effect by replacing the last sentence
of 12.5  class.free paragraph 4 with something like:
    After removing all placement deallocation functions, the result of
the lookup shall contain an unambiguous and accessible deallocation
function.
[/quote]

The problem is, after removing all placement deallocation functions,
there should be only one usual(non-placement) deallocation function
left( 3.7.3.2/2 clearly indicates that there could be only one
usual(non-placement) deallocation function, which is either operator
delete(void*), or operator delete(void*, size_t) if the previous one
isn't declared), so how could there be any ambiguity?

[Note that the existence of operator delete(void*) will make operator
delete(void*, size_t) a placement deallocation function, thus being
removed from the lookup set.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]