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

4612. Specify the details of std::nullopt_t

Section: 22.5.5 [optional.nullopt] Status: New Submitter: Jiang An Opened: 2026-08-11 Last modified: 2026-08-15

Priority: Not Prioritized

View all other issues in [optional.nullopt].

View all issues with New status.

Discussion:

LWG 4497(i) specified that std::nullopt_t is copyable and three-way comparable. However, during implementing and testing its resolution in libc++, it was found that almost no intended operation is specified to be have desired property - being noexcept or trivial, or even constexpr for some special member functions. Maybe we should specify the details of std::nullopt_t more precisely.

Proposed resolution:

This wording is relative to N5054.

  1. Modify 22.5.5 [optional.nullopt] as indicated:

    [Drafting note: It will become redundant to specify that nullopt_t is empty, non-aggregate, and modeling certain concepts. In current implementations, nullopt_t does have some member type, so perhaps we shouldn't specify lack of member types.]

    struct nullopt_t{see below
      // unspecified constructors
    
      friend strong_ordering operator<=>(nullopt_t, nullopt_t) = default;
    };
    inline constexpr nullopt_t nullopt(unspecified);
    

    -1- The struct nullopt_t is an empty class type used as a unique type to indicate the state of not containing a value for optional objects. In particular, optional<T> has a constructor with nullopt_t as a single argument; this indicates that an optional object not containing a value shall be constructed.

    -2- Type nullopt_t does not have a default constructor or an initializer-list constructor, and is not an aggregate. nullopt_t models copyable and three_way_comparable<strong_ordering>base class, non-static data member, default constructor, initializer-list constructor, or explicitly declared non-static member function that is not a constructor. All special member functions of nullopt_t are implicitly declared.