Title
Specify the details of `std::nullopt_t`
Status
new
Section
[optional.nullopt]
Submitter
Jiang An

Created on 2026-08-11.00:00:00 last changed 1 week ago

Messages

Date: 2026-08-25.16:39:00

Proposed resolution:

This wording is relative to N5054.

  1. Modify [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 a 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> any 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.

Date: 2026-08-25.16:39:00

LWG 4497 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 have desirable properties - being `noexcept` or trivial, or even `constexpr` for some special member functions. Maybe we should specify the details of `std::nullopt_t` more precisely.

History
Date User Action Args
2026-08-15 12:37:37adminsetmessages: + msg16553
2026-08-11 00:00:00admincreate