Title
Non-eligible trivial default constructors
Status
review
Section
11.4.5.2 [class.default.ctor]
Submitter
Roy Jacobson

Created on 2022-11-26.00:00:00 last changed 4 months ago

Messages

Date: 2024-05-31.21:07:31

Proposed resolution (approved by CWG 2024-05-31):

Change in 11.4.5.2 [class.default.ctor] paragraph 3 as follows:

A default constructor for class X is trivial if it is not user-provided and if:
  • its class X has no virtual functions (11.7.3 [class.virtual]) and no virtual base classes (11.7.2 [class.mi]), and
  • no non-static data member of its class X has a default member initializer (11.4 [class.mem]), and
  • all the direct base classes of its class have trivial default constructors, and
  • the constructor selected to default-initialize each direct base class subobject of X is trivial,
  • for all the non-static data members of its class that are of class type (or array thereof), each such class has a trivial default constructor.
  • for each direct non-static data member of X that is of class type (or array thereof), the constructor selected to default-initialize that member (or an array element of that member) is trivial.
Otherwise, the default constructor is non-trivial.
Date: 2024-05-31.21:07:31

(From submission #521.)

Consider:

  template <class T>
  struct A {
    A() requires (false) = default;
    A() : t(42) {}
    T t;
  };

  struct B : A<int> {};

According to the current wording, class B has a trivial default constructor, which is undesirable.

History
Date User Action Args
2024-06-28 19:56:12adminsetstatus: tentatively ready -> review
2024-05-31 21:07:31adminsetmessages: + msg7717
2024-05-31 21:07:31adminsetstatus: review -> tentatively ready
2024-05-17 22:24:28adminsetstatus: open -> review
2022-11-26 00:00:00admincreate