Title
visit is underconstrained
Status
resolved
Section
[variant.visit]
Submitter
Casey Carter

Created on 2018-01-23.00:00:00 last changed 44 months ago

Messages

Date: 2021-04-19.14:17:33

Proposed resolution:

This wording is relative to N4727.

  1. Modify [variant.visit] as indicated:

    template<class Visitor, class... Variants>
      constexpr see below visit(Visitor&& vis, Variants&&... vars);
    

    […]

    -4- Throws: bad_variant_access if any variant in vars is valueless_by_exception()(vars.valueless_by_exception() || ...) is true.

    -5- Complexity: […]

    -?- Remarks: This function shall not participate in overload resolution unless remove_cvref_t<Variantsi> is a specialization of variant for all 0 <= i < n.

Date: 2021-04-19.00:00:00

[ 2021-04-19 P2162R2 was adopted at February 2021 plenary. Status changed: Tentatively Resolved → Resolved. ]

Date: 2020-11-15.00:00:00

[ 2020-11-18; this will be resolved by P2162. ]

Date: 2018-06-18.00:00:00

[ 2018-06-18 after reflector discussion ]

Priority set to 2; status to LEWG

Date: 2017-01-15.00:00:00

[ 2018-01-24, Daniel comments ]

This issue should be reviewed in common with LWG 2970.

Date: 2018-01-23.00:00:00

std::visit accepts a parameter pack of forwarding references named vars whose types are the parameter pack Variants. Despite that:

  1. the names of both packs are variants of "variant",
  2. para 1 passes the types in Variants (modified) to variant_size_v,
  3. para 3 uses the expression varsi.index(),
  4. para 4 says "...if any variant in vars is valueless_by_exception, and
  5. para 5 mentions "..the number of alternative types of Variants0"
the Requires element imposes no explicit requirements on the types in Variants. Notably, the Variants are not required to be variants. This lack of constraints appears to be simply an oversight.

History
Date User Action Args
2021-04-19 14:17:33adminsetmessages: + msg11766
2020-11-18 12:14:32adminsetmessages: + msg11617
2020-11-18 12:14:32adminsetstatus: lewg -> resolved
2018-06-19 05:49:11adminsetmessages: + msg9925
2018-06-19 05:49:11adminsetstatus: new -> lewg
2018-01-24 20:29:21adminsetmessages: + msg9630
2018-01-24 00:48:55adminsetmessages: + msg9627
2018-01-23 00:00:00admincreate