2740. constexpr optional<T>::operator->

Section: 23.6.3.5 [optional.observe] Status: C++17 Submitter: Agustín K-ballo Bergé Opened: 2016-07-02 Last modified: 2017-07-30

Priority: 0

View all other issues in [optional.observe].

View all issues with C++17 status.

Discussion:

optional<T>::operator->s are constrained to be constexpr functions only when T is not a type with an overloaded unary operator&. This constrain comes from the need to use addressof (or a similar mechanism), and the inability to do so in a constant expression in C++14. Given that addressof is now constexpr, this constrain is no longer needed.

[2016-07 Chicago]

Monday: P0 - tentatively ready

Proposed resolution:

This wording is relative to N4594.

  1. Modify [optional.object.observe] as indicated:

    constexpr T const* operator->() const;
    constexpr T* operator->();
    

    -1- Requires: *this contains a value.

    -2- Returns: val.

    -3- Throws: Nothing.

    -4- Remarks: Unless T is a user-defined type with overloaded unary operator&, tThese functions shall be constexpr functions.