Title
default_delete's default constructor should be trivial
Status
c++11
Section
[unique.ptr.dltr.dflt]
Submitter
Daniel Krügler

Created on 2010-09-12.00:00:00 last changed 161 months ago

Messages

Date: 2010-11-23.13:22:14

Proposed resolution:

The following wording changes are against N3126.

  1. Change the synopsis of the primary template definition of default_delete in [unique.ptr.dltr.dflt] as indicated:
    namespace std {
      template <class T> struct default_delete {
        constexpr default_delete() = default;
        template <class U> default_delete(const default_delete<U>&);
        void operator()(T*) const;
      };
    }
    
  2. Remove the prototype specification of the default_delete default constructor in [unique.ptr.dltr.dflt]/1. This brings it in harmony with the style used in the partial specialization default_delete<T[]>. Since there are neither implied nor explicit members, there is no possibility to misinterpret what the constructor does:
    constexpr default_delete();
    

    1 Effects: Default constructs a default_delete object.

  3. Change the synopsis of the partial specialization of default_delete in [unique.ptr.dltr.dflt1] as indicated:
    namespace std {
      template <class T> struct default_delete<T[]> {
        constexpr default_delete() = default;
        void operator()(T*) const;
        template <class U> void operator()(U*) const = delete;
      };
    }
Date: 2010-11-23.13:22:14

[ Adopted at 2010-11 Batavia ]

Date: 2010-10-21.19:47:27

[ Post-Rapperswil ]

Moved to Tentatively Ready after 5 positive votes on c++std-lib.

Date: 2010-09-12.00:00:00

The current working draft does specify the default c'tor of default_delete in a manner to guarantee static initialization for default-constructed objects of static storage duration as a consequence of the acceptance of the proposal n2976 but this paper overlooked the fact that the suggested declaration does not ensure that the type will be a trivial type. The type default_delete was always considered as a simple wrapper for calling delete or delete[], respectivly and should be a trivial type.

In agreement with the new settled core language rules this easy to realize by just changing the declaration to

constexpr default_delete() = default;

This proposal also automatically solves the problem, that the semantics of the default constructor of the partial specialization default_delete<T[]> is not specified at all. By defaulting its default constructor as well, the semantics are well-defined.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-11-23 13:22:14adminsetmessages: + msg5409
2010-11-14 13:10:57adminsetstatus: voting -> wp
2010-11-08 14:14:39adminsetstatus: ready -> voting
2010-10-21 19:47:27adminsetmessages: + msg4878
2010-10-21 19:47:27adminsetmessages: + msg4877
2010-09-12 00:00:00admincreate