What is the point of deleted destructor?

前端 未结 1 362
礼貌的吻别
礼貌的吻别 2020-12-19 16:43

I come across the rule (section N3797::12.8/11 [class.copy])

An implicitly-declared copy/move constructor is an inline public member of

相关标签:
1条回答
  • 2020-12-19 17:37

    The rationale for that bullet is covered in defect report 1191: Deleted subobject destructors and implicitly-defined constructors which says:

    Consider the following example:

    struct A {
       A();
       ~A() = delete;
    };
    
    struct B: A { };
    B* b = new B;
    

    Under the current rules, B() is not deleted, but is ill-formed because it calls the deleted ~A::A() if it exits via an exception after the completion of the construction of A. A deleted subobject destructor should be added to the list of reasons for implicit deletion in 12.1 [class.ctor] and 12.8 [class.copy].

    and the proposed resolution was to add the bullet you note above and the same wording to the following section 12.1 [class.ctor] paragraph 5:

    any direct or virtual base class or non-static data member has a type with a destructor that is deleted or inaccessible from the defaulted default constructor.

    0 讨论(0)
提交回复
热议问题