Title
Deleted operator delete and virtual destructors
Status
cd1
Section
11.4.7 [class.dtor]
Submitter
Mike Miller

Created on 2008-02-15.00:00:00 last changed 161 months ago

Messages

Date: 2008-09-15.00:00:00

[Voted into the WP at the September, 2008 meeting.]

Date: 2008-06-15.00:00:00

Proposed resolution (June, 2008):

Change 11.4.7 [class.dtor] paragraph 10 as follows:

If the result of this lookup is ambiguous or inaccessible, or if the lookup selects a placement deallocation function or a function with a deleted definition (9.5 [dcl.fct.def]), the program is ill-formed.
Date: 2008-02-15.00:00:00

Deallocation functions can't be virtual because they are static member functions; however, according to 11.11 [class.free] paragraph 7, they behave like virtual functions when the class's destructor is virtual:

Since member allocation and deallocation functions are static they cannot be virtual. [Note: however, when the cast-expression of a delete-expression refers to an object of class type, because the deallocation function actually called is looked up in the scope of the class that is the dynamic type of the object, if the destructor is virtual, the effect is the same.

Because the intent is to make any use of a deleted function diagnosable at compile time, a virtual deleted function can neither override nor be overridden by a non-deleted function, as described in 11.7.3 [class.virtual] paragraph 14:

A function with a deleted definition (9.5 [dcl.fct.def]) shall not override a function that does not have a deleted definition. Likewise, a function that does not have a deleted definition shall not override a function with a deleted definition.

One would assume that a similar kind of prohibition is needed for deallocation functions in a class hierarchy with virtual destructors, but it's not clear that the current specification says that. 9.5 [dcl.fct.def] paragraph 10 says,

A program that refers to a deleted function implicitly or explicitly, other than to declare it, is ill-formed.

Furthermore, the deallocation function is looked up at the point of definition of a virtual destructor (11.4.7 [class.dtor] paragraph 11), and the function found by this lookup is considered to be “used” (6.3 [basic.def.odr] paragraph 2). However, it's not completely clear that this “use” constitutes a “reference” in the sense of 9.5 [dcl.fct.def] paragraph 10, especially in a program in which an object of a type that would call that deallocation function is never deleted.

Suggested resolution:

Augment the list of lookup results from a virtual destructor that render a program ill-formed in 11.4.7 [class.dtor] paragraph 10 to include a deleted function:

If the result of this lookup is ambiguous or inaccessible, or if the lookup selects a placement deallocation function or a function with a deleted definition (9.5 [dcl.fct.def]), the program is ill-formed.
History
Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1827
2008-10-05 00:00:00adminsetstatus: ready -> cd1
2008-06-29 00:00:00adminsetmessages: + msg1674
2008-06-29 00:00:00adminsetstatus: open -> ready
2008-02-15 00:00:00admincreate