Title
Should a trivial class type be a literal type?
Status
cd1
Section
6.8 [basic.types]
Submitter
Alisdair Meredith

Created on 2007-08-08.00:00:00 last changed 197 months ago

Messages

Date: 2008-06-15.00:00:00

[Voted into the WP at the June, 2008 meeting.]

Date: 2008-02-15.00:00:00

Proposed resolution (February, 2008):

Change 6.8 [basic.types] paragraph 10 as follows:

A type is a literal type if it is:
  • a scalar type; or
  • a class type (Clause 11 [class]) with
    • a trivial copy constructor,
    • a trivial destructor,
    • a trivial default constructor or at least one constexpr constructor other than the copy constructor,
    • no virtual base classes, and
    • all non-static data members and base classes of literal types; or
  • an array of literal type.
Date: 2008-07-27.00:00:00

The original proposed wording for 6.8 [basic.types] paragraph 11 required a constexpr constructor for a literal class only “if the class has at least one user-declared constructor.” This wording was dropped during the review by CWG out of a desire to ensure that literal types not have any uninitialized members. Thus, a class like

    struct pixel {
        int x, y;
    };

is not a literal type. However, if an object of that type is aggregate-initialized or value-initialized, there can be no uninitialized members; the missing wording should be restored in order to permit use of expressions like pixel().x as constant expressions.

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: dr -> cd1
2008-07-27 00:00:00adminsetmessages: + msg1739
2008-06-29 00:00:00adminsetstatus: ready -> dr
2008-03-17 00:00:00adminsetmessages: + msg1589
2008-03-17 00:00:00adminsetstatus: open -> ready
2007-08-08 00:00:00admincreate