This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TS status.

2745. [fund.ts.v2] Implementability of LWG 2451

Section: 5.3 [fund.ts.v2::optional.object] Status: TS Submitter: Casey Carter Opened: 2016-07-10 Last modified: 2018-07-08

Priority: 0

View all other issues in [fund.ts.v2::optional.object].

View all issues with TS status.

Discussion:

Addresses: fund.ts.v2

LWG 2451(i) adds conditionally explicit converting constructors to optional<T> that accept:

  1. Types convertible to T: template <class U> constexpr optional(T&&);
  2. Rvalue optional<U> when U&& is convertible to T: template <class U> constexpr optional(optional<U>&&);
  3. Lvalue const optional<U> when const U& is convertible to T: template <class U> constexpr optional(const optional<U>&);

All three of these constructors are required to be constexpr "If T's selected constructor is a constexpr constructor". While this is not problematic for #1, it is not possible in the current language to implement signatures #2 and #3 as constexpr functions for the same reasons that optional's non-converting constructors from optional<T>&& and const optional<T>& cannot be constexpr.

We should remove the "constexpr" specifier from the declarations of the conditionally explicit converting constructors that accept optional<U>&& and const optional<U>&, and strike the remarks requiring these constructors to be constexpr.

[2016-07 Chicago]

Monday: P0 - tentatively ready

This needs to be considered for C++17 as well

Proposed resolution:

This wording is relative to N4600.

Wording relative to N4600 + LWG 2451(i), although it should be noted that this resolution should be applied wherever LWG 2451(i) is applied, be that to the fundamentals TS or the specification of optional in the C++ Working Paper.

  1. Edit 22.5.3 [optional.optional] as indicated:

    template <class T>
    class optional
    {
    public:
      typedef T value_type;
    
      // 5.3.1, Constructors
      […]
      template <class U> constexpr optional(U&&);
      template <class U> constexpr optional(const optional<U>&);
      template <class U> constexpr optional(optional<U<&&);
      […]
    };
    
  2. In 5.3.1 [fund.ts.v2::optional.object.ctor], modify the new signature specifications added by LWG 2451(i)

    template <class U>
      constexpr optional(const optional<U>& rhs);
    

    […]

    -48- Remarks: If T's selected constructor is a constexpr constructor, this constructor shall be a constexpr constructor. This constructor shall not participate in overload resolution unless […]

    template <class U>
      constexpr optional(optional<U>&& rhs);
    

    […]

    -53- Remarks: If T's selected constructor is a constexpr constructor, this constructor shall be a constexpr constructor. This constructor shall not participate in overload resolution unless […]