Title
Overly aggressive rule for deleting the destructor of a union
Status
open
Section
11.4.7 [class.dtor]
Submitter
Barry Revzin

Created on 2025-07-03.00:00:00 last changed 1 month ago

Messages

Date: 2025-07-27.10:49:11

Suggested resolution:

Change in 11.4.7 [class.dtor] paragraph 7 as follows:

A defaulted destructor for a class X is defined as deleted if
  • X is a non-union class and any non-variant potentially constructed subobject has class type M (or possibly multidimensional array thereof) where M has a destructor that is deleted or is inaccessible from the defaulted destructor,
  • X is a union and there is a subobject S of class type M (or possibly multi-dimensional array thereof) where M has a destructor that is deleted, inaccessible from the defaulted destructor, or non-trivial, and either
    • overload resolution to select a constructor to default-initialize an object of type X either fails or selects a constructor that is either deleted or not trivial user-provided, or
    • X has a variant member V of class type M (or possibly multi-dimensional array thereof) where V S has a default member initializer and M has a destructor that is non-trivial, or,
  • for a virtual destructor, lookup of the non-array deallocation function results in an ambiguity or in a function that is deleted or inaccessible from the defaulted destructor.
Date: 2025-07-03.00:00:00

(From submission #722.)

Paper P3074R7 added an overly aggressive rule to delete destructors of unions, making the following example have a deleted destructor:

  union U {
    U(int i) : i(i) { }
    int i;
  };
History
Date User Action Args
2025-07-27 10:49:11adminsetmessages: + msg8055
2025-07-03 00:00:00admincreate