Title
Constexpr constructor templates and literal types
Status
c++11
Section
6.8 [basic.types]
Submitter
Gabriel Dos Reis

Created on 2009-10-16.00:00:00 last changed 96 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):

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 Clause 11 [class]) with that

    • a trivial copy constructor,

    • no non-trivial move constructor,

    • has a trivial destructor,

    • a trivial default constructor or is an aggregate type (9.4.2 [dcl.init.aggr]) or has at least one constexpr constructor other than the or constructor template that is not a copy or move constructor, and

    • has all non-static data members and base classes of literal types; or

  • an array of literal type.

This resolution also resolves issues 1071 and 1198.

Date: 2009-10-16.00:00:00

6.8 [basic.types] paragraph 10 requires that a class have at least one constexpr constructor other than the copy constructor in order to be considered a literal type. However, a constexpr constructor template might be instantiated in such a way that the constexpr specifier is ignored (9.2.6 [dcl.constexpr] paragraph 5). It is therefore not known whether a class with a constexpr constructor template is a literal type or not until the constructor template is specialized, which could mean that an example like

    struct IntValue {
      template<typename T>
        constexpr IntValue(T t) : val(t) { }

      constexpr intmax_t get_value() { return val; }

     private:
       intmax_t val;
    };

is ill-formed, because it is an error to declare a member function (like get_value()) of a non-literal class to be constexpr (9.2.6 [dcl.constexpr] paragraph 6).

6.8 [basic.types] paragraph 10 should be revised so that either a constexpr constructor or constexpr constructor template allows a class to be a literal type.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3299
2011-04-10 00:00:00adminsetstatus: ready -> fdis
2010-11-29 00:00:00adminsetmessages: + msg3048
2010-11-29 00:00:00adminsetstatus: drafting -> ready
2010-08-23 00:00:00adminsetstatus: open -> drafting
2009-10-16 00:00:00admincreate