This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-18


1574. Explicitly-defaulted constexpr functions in wrapper templates

Section: 9.5.2  [dcl.fct.def.default]     Status: NAD     Submitter: Daniel Krügler     Date: 2012-10-16

According to 9.5.2 [dcl.fct.def.default] paragraph 2,

An explicitly-defaulted function may be declared constexpr only if it would have been implicitly declared as constexpr...

This is relevant for wrapper functions like

  template<class T> struct wrap {
    T t;
    constexpr wrap() = default;
    constexpr wrap(const wrap&) = default;
  };

It is not clear how the new wording for constexpr member functions of class templates in the proposed resolution issue 1358 affects this:

If the instantiated template specialization of a constexpr function template or member function of a class template would fail to satisfy the requirements for a constexpr function or constexpr constructor, that specialization is still a constexpr function or constexpr constructor, even though a call to such a function cannot appear in a constant expression.

Rationale (April, 2013):

The specification is as intended. The defaulted constructor will be constexpr if it can be, so it should not be explicitly declared constexpr in order to avoid the problems mentioned.