Title
std::optional<T> is ill-formed is T is an array
Status
c++20
Section
[optional.optional]
Submitter
Jonathan Wakely

Created on 2019-03-18.00:00:00 last changed 23 months ago

Messages

Date: 2019-06-16.19:32:21

Proposed resolution:

This wording is relative to N4810.

  1. In [utility.arg.requirements], edit Table 30 — "Cpp17Destructible requirements" as indicated:

    Table 30 — Cpp17Destructible requirements
    Expression Post-condition
    u.~T() All resources owned by u are reclaimed, no exception is propagated.
    [Note: Array types and non-object types are not Cpp17Destructible. — end note]
  1. Modify [optional.optional] as indicated:

    -3- T shall be a object type other than cv in_place_t or cv nullopt_t and shall satisfythat meets the Cpp17Destructible requirements (Table 30).

  1. Modify [variant.variant] as indicated:

    -2-All types in Types shall be (possibly cv-qualified) object types that are not arraysmeet the Cpp17Destructible requirements (Table 30).

Date: 2019-06-16.00:00:00

[ 2019-06-16 Moved to "Tentatively Ready" based on five positive votes on the reflector ]

Date: 2019-03-26.00:00:00

[ 2019-03-26 Marshall provides updated resolution based on reflector discussion ]

Date: 2019-03-26.14:12:25

[optional.optional] appears to allow arrays:

T shall be an object type other than cv in_place_t or cv nullopt_t and shall satisfy the Cpp17Destructible requirements (Table 30).

But instantiating it fails, because value_or attempts to return T by value, which isn't possible for an array type.

Existing practice seems to be to reject array types. Libstdc++ and libc++ give an error for the signature of value_or, and MSVC fails a static assert saying the type needs to be destructible (which is misleading, because int[2] is destructible, but either way it's ill-formed).

Previous resolution [SUPERSEDED]:

This wording is relative to N4810.

  1. Modify [optional.optional] as indicated:

    -3- T shall be an non-array object type other than cv in_place_t or cv nullopt_t and shall satisfy the Cpp17Destructible requirements (Table 30).

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2019-07-22 15:46:37adminsetstatus: voting -> wp
2019-06-17 05:25:36adminsetstatus: ready -> voting
2019-06-16 19:32:21adminsetmessages: + msg10451
2019-06-16 19:32:21adminsetstatus: new -> ready
2019-03-26 14:12:25adminsetmessages: + msg10381
2019-03-19 19:16:08adminsetmessages: + msg10367
2019-03-18 00:00:00admincreate