Title
Literal class types and trivial default constructors
Status
c++11
Section
6.8 [basic.types]
Submitter
Daniel Krügler

Created on 2010-06-02.00:00:00 last changed 131 months ago

Messages

Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting.]

Date: 2010-11-15.00:00:00

Proposed resolution (November, 2010):

This issue is resolved by the resolution of issue 981.

Date: 2010-06-02.00:00:00

According to 6.8 [basic.types] paragraph 10, one of the requirements for a literal class type is

  • a trivial default constructor or at least one constexpr constructor other than the copy or move constructor

This rule has unfortunate consequences. For example, in

    struct A { int x; };
    struct B: A { int y; };

B is a literal type, even though it is impossible to initialize a constant of that type. Conversely, in

    struct C {
        int a, b;
        constexpr C(int x, int y): a(x), b(y) { }
    };
    struct D {
        int x;
        C c;
    };

D is not a literal type, even though it could be initialized as an aggregate.

It would be an improvement to replace the requirement for a trivial default constructor with a requirement that the class be an aggregate.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3300
2011-04-10 00:00:00adminsetstatus: ready -> fdis
2010-11-29 00:00:00adminsetmessages: + msg3049
2010-11-29 00:00:00adminsetstatus: drafting -> ready
2010-06-02 00:00:00admincreate