Title
variant copy constructor missing noexcept(see below)
Status
voting
Section
[variant.ctor]
Submitter
Peter Dimov

Created on 2017-06-27.00:00:00 last changed 2 days ago

Messages

Date: 2025-10-27.10:00:32

Proposed resolution:

This wording is relative to P5014.

  1. Edit [variant.variant], class template variant synopsis, as indicated:

    template <class... Types>
      class variant {
      public:
        // 23.7.3.1, constructors
        constexpr variant() noexcept(see below);
        variant(const variant&) noexcept(see below);
        variant(variant&&) noexcept(see below);
        […]
      };
    
  2. Edit [variant.ctor] as indicated:

    variant(const variant& w) noexcept(see below);
    

    […]

    -8- Remarks: This function is defined as deleted unless is_copy_constructible_v<Ti> is true for all i. The exception specification is equivalent to the logical and of is_nothrow_copy_constructible_v<Ti> for all i.

Date: 2025-10-15.00:00:00

[ 2025-10-23; Reflector poll. ]

Set status to Tentatively Ready after five votes in favour during reflector poll.

Date: 2025-10-15.00:00:00

[ 2025-10-20; Jonathan provides updated wording ]

Date: 2025-10-20.17:46:44

[ Wrocław 2024-11-18; LEWG approves the direction ]

In P0088R1 the copy constructor was conditionally noexcept in the synopsis, but not the detailed description. This was pointed out during LWG review in Jacksonville. The approved paper, P008R3, doesn't have it in either place.

This wording is relative to N4659.

  1. Edit [variant.variant], class template variant synopsis, as indicated:

    template <class... Types>
      class variant {
      public:
        // 23.7.3.1, constructors
        constexpr variant() noexcept(see below);
        variant(const variant&) noexcept(see below);
        variant(variant&&) noexcept(see below);
        […]
      };
    
  2. Edit [variant.ctor] as indicated:

    variant(const variant& w) noexcept(see below);
    

    […]

    -8- Remarks: This function shall not participate in overload resolution unless is_copy_constructible_v<Ti> is true for all i. The expression inside noexcept is equivalent to the logical AND of is_nothrow_copy_constructible_v<Ti> for all i.

Date: 2017-07-12.01:58:24

[ 2017-07 Toronto Tuesday PM issue prioritization ]

Status to LEWG

Date: 2017-06-27.00:00:00

The copy constructor of std::variant is not conditionally noexcept (I think it was in the original proposal.)

It should be, for two reasons: first, this would be consistent with the other three constructors

constexpr variant() noexcept(see below);

variant(variant&&) noexcept(see below);

template <class T>
constexpr variant(T&&) noexcept(see below);

and second, variant itself makes use of is_nothrow_copy_constructible, so it's inconsistent for it to take a stance against it.

History
Date User Action Args
2025-10-30 17:45:31adminsetstatus: ready -> voting
2025-10-27 10:00:32adminsetmessages: + msg15459
2025-10-27 10:00:32adminsetstatus: open -> ready
2025-10-20 17:46:44adminsetmessages: + msg15288
2024-11-19 16:09:33adminsetmessages: + msg14459
2024-11-19 16:09:33adminsetstatus: lewg -> open
2017-07-12 01:58:24adminsetmessages: + msg9354
2017-07-12 01:58:24adminsetstatus: new -> lewg
2017-06-27 20:14:55adminsetmessages: + msg9301
2017-06-27 00:00:00admincreate