Title
Non-constexpr instances of constexpr constructor templates
Status
cd1
Section
9.2.6 [dcl.constexpr]
Submitter
Mike Miller

Created on 2007-08-12.00:00:00 last changed 34 months ago

Messages

Date: 2008-09-15.00:00:00

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

Date: 2008-06-15.00:00:00

Proposed resolution (June, 2008):

[Drafting note: This resolution goes beyond the problem described in the issue discussion, which is one aspect of the general failure of the existing wording to deal consistently with the distinctions between constexpr functions and constexpr constructors. The wording below attempts to rectify that problem systematically.]

  1. Change 9.2.6 [dcl.constexpr] paragraph 2 as follows:

  2. A constexpr specifier used in a function declaration the declaration of a function that is not a constructor declares that function to be a constexpr function. Similarly, a constexpr specifier used in a constructor declaration declares that constructor to be a constexpr constructor. Constexpr functions and constexpr constructors are implicitly inline (9.2.3 [dcl.fct.spec]). A constexpr function shall not be virtual (10.3).
  3. Change 9.2.6 [dcl.constexpr] paragraph 3 as follows:

  4. The definition of a constexpr function shall satisfy the following constraints:

    • it shall not be virtual (11.7.3 [class.virtual])

    • its return type shall be a literal type

    • each of its parameter types shall be a literal type

    • its function-body shall be a compound-statement of the form

        { return expression ; }

      where expression is a potential constant expression (7.7 [expr.const])

    • every implicit conversion used in converting expression to the function return type (9.4 [dcl.init]) shall be one of those allowed in a constant expression (7.7 [expr.const]).

    [Example:...

  5. Change 9.2.6 [dcl.constexpr] paragraph 4 as follows:

  6. The definition of a constexpr constructor shall satisfy the following constraints:

    • each of its parameter types shall be a literal type

    • its function-body shall not be a function-try-block

    • the compound-statement of its function-body shall be empty

    • every non-static data member and base class sub-object shall be initialized (11.9.3 [class.base.init])

    • every constructor involved in initializing non-static data members and base class sub-objects invoked by a mem-initializer shall be a constexpr constructor invoked with potential constant expression arguments, if any.

    • every constructor argument and full-expression in a mem-initializer shall be a potential constant expression

    • every implicit conversion used in converting a constructor argument to the corresponding parameter type and converting a full-expression to the corresponding member type shall be one of those allowed in a constant expression.

    A trivial copy constructor is also a constexpr constructor. [Example: ...

  7. Change 9.2.6 [dcl.constexpr] paragraph 5 as follows:

  8. If the instantiated template specialization of a constexpr function template would fail to satisfy the requirements for a constexpr function or constexpr constructor, the constexpr specifier is ignored and the specialization is not a constexpr function.
  9. Change 9.2.6 [dcl.constexpr] paragraph 6 as follows:

  10. A constexpr specifier used in for a non-static member function definition that is not a constructor declares that member function to be const (11.4.3 [class.mfct.non.static]). [Note: ...
Date: 2022-02-18.07:47:23

Suggested resolution:

Change the wording of 9.2.6 [dcl.constexpr] paragraph 5 as indicated:

If the instantiated template specialization of a constexpr function template would fail to satisfy the requirements for a constexpr function or constexpr constructor, as appropriate to the function template, the constexpr specifier is ignored and the specialization is not a constexpr function or constexpr constructor.
Date: 2022-02-18.07:47:23

According to 9.2.6 [dcl.constexpr] paragraph 5,

If the instantiated template specialization of a constexpr function template would fail to satisfy the requirements for a constexpr function, the constexpr specifier is ignored and the specialization is not a constexpr function.

One would expect to see a similar provision for an instantiated constructor template (because the requirements for a constexpr function [paragraph 3] are different from the requirements for a constexpr constructor [paragraph 4]), but there is none; constexpr constructor templates are not mentioned.

History
Date User Action Args
2022-02-18 07:47:23adminsetmessages: + msg6697
2008-10-05 00:00:00adminsetmessages: + msg1817
2008-10-05 00:00:00adminsetstatus: ready -> cd1
2008-06-29 00:00:00adminsetmessages: + msg1679
2008-06-29 00:00:00adminsetstatus: drafting -> ready
2007-10-09 00:00:00adminsetstatus: open -> drafting
2007-08-12 00:00:00admincreate