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

3052. visit is underconstrained

Section: 20.7.7 [variant.visit] Status: LEWG Submitter: Casey Carter Opened: 2018-01-23 Last modified: 2019-12-11

Priority: 2

View all other issues in [variant.visit].

View all issues with LEWG status.


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.

[2018-01-24, Daniel comments]

This issue should be reviewed in common with LWG 2970.

[2018-06-18 after reflector discussion]

Priority set to 2; status to LEWG

Proposed resolution:

This wording is relative to N4727.

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