Title
When is a deallocation function "used?"
Status
cd1
Section
6.3 [basic.def.odr]
Submitter
Mike Miller

Created on 2000-11-07.00:00:00 last changed 26 months ago

Messages

Date: 2002-10-15.00:00:00

[Moved to DR at October 2002 meeting.]

Date: 2002-10-15.00:00:00

[Moved to DR at October 2002 meeting.]

Date: 2001-10-15.00:00:00

Proposed resolution (10/01):

In 6.3 [basic.def.odr] paragraph 2, add the indicated text:

An allocation or deallocation function for a class is used by a new expression appearing in a potentially-evaluated expression as specified in 7.6.2.8 [expr.new] and 11.4.11 [class.free]. A deallocation function for a class is used by a delete expression appearing in a potentially-evaluated expression as specified in 7.6.2.9 [expr.delete] and 11.4.11 [class.free]. A non-placement allocation or deallocation function for a class is used by the definition of a constructor of that class. A non-placement deallocation function for a class is used by the definition of the destructor of that class, or by being selected by the lookup at the point of definition of a virtual destructor (11.4.7 [class.dtor]). [Footnote: An implementation is not required to call allocation and deallocation functions from constructors or destructors; however, this is a permissible implementation technique.]

Date: 2001-04-15.00:00:00

Notes from 04/01 meeting:

The consensus was in favor of requiring that any declared non-placement operator delete member function be defined if the destructor for the class is defined (whether virtual or not), and similarly for a non-placement operator new if a constructor is defined.

Date: 2022-11-20.07:54:16

6.3 [basic.def.odr] paragraph 2 says that a deallocation function is "used" by a new-expression or delete-expression appearing in a potentially-evaluated expression. 6.3 [basic.def.odr] paragraph 3 requires only that "used" functions be defined.

This wording runs afoul of the typical implementation technique for polymorphic delete-expressions in which the deallocation function is invoked from the virtual destructor of the most-derived class. The problem is that the destructor must be defined, because it's virtual, and if it contains an implicit reference to the deallocation function, the deallocation function must also be defined, even if there are no relevant new-expressions or delete-expressions in the program.

For example:

        struct B { virtual ~B() { } };

        struct D: B {
            void operator delete(void*);
            ~D() { }
        };

Is it required that D::operator delete(void*) be defined, even if no B or D objects are ever created or deleted?

Suggested resolution: Add the words "or if it is found by the lookup at the point of definition of a virtual destructor (11.4.7 [class.dtor])" to the specification in 6.3 [basic.def.odr] paragraph 2.

History
Date User Action Args
2022-02-18 07:47:23adminsetmessages: + msg6663
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2003-04-25 00:00:00adminsetstatus: dr -> wp
2002-11-08 00:00:00adminsetmessages: + msg768
2002-11-08 00:00:00adminsetstatus: ready -> dr
2002-05-10 00:00:00adminsetstatus: review -> ready
2001-11-09 00:00:00adminsetstatus: drafting -> review
2001-09-12 00:00:00adminsetmessages: + msg524
2001-05-20 00:00:00adminsetmessages: + msg490
2001-05-20 00:00:00adminsetstatus: open -> drafting
2000-11-07 00:00:00admincreate