Title
NSDMIs and deleted union default constructors
Status
cd4
Section
11.4.5 [class.ctor]
Submitter
Daveed Vandevoorde

Created on 2015-02-12.00:00:00 last changed 87 months ago

Messages

Date: 2015-10-15.00:00:00

Proposed resolution (October, 2015):

Change 11.4.5 [class.ctor] paragraph 4 as follows:

...A defaulted default constructor for class X is defined as deleted if:

  • X is a union that has a variant member with a non-trivial default constructor and no variant member of X has a default member initializer,

  • X is a union-like non-union class that has a variant member M with a non-trivial default constructor and no variant member of the anonymous union containing M has a default member initializer,

  • ...

Date: 2015-05-15.00:00:00

Notes from the May, 2015 meeting:

An NSDMI is basically syntactic sugar for a mem-initializer, so the presence of one should be treated as if a user-declared default constructor were present.

Date: 2016-02-15.00:00:00

[Adopted at the February, 2016 meeting.]

According to 11.4.5 [class.ctor] paragraph 4 says,

A defaulted default constructor for class X is defined as deleted if:

  • X is a union-like class that has a variant member with a non-trivial default constructor,

  • ...

This should make the following example ill-formed:

  struct S {
    S();
  };
  union U {
    S s{};
  } u;

because the default constructor of U is deleted. However, both clang and g++ accept this without error. Should the rule be relaxed for a union with an NSDMI?

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: ready -> cd4
2015-11-10 00:00:00adminsetmessages: + msg5580
2015-11-10 00:00:00adminsetstatus: drafting -> ready
2015-05-25 00:00:00adminsetmessages: + msg5509
2015-02-12 00:00:00admincreate