Title
Diagnose out of bounds tuple_element/variant_alternative
Status
c++20
Section
[pair.astuple][variant.helper]
Submitter
Agustín K-ballo Bergé

Created on 2017-06-10.00:00:00 last changed 45 months ago

Messages

Date: 2017-06-12.17:47:12

Proposed resolution:

This wording is relative to N4659.

  1. Modify [utility.syn], header <utility> synopsis, as indicated:

    […]
    
    // [pair.astuple], tuple-like access to pair
    template <class T> class tuple_size;
    template <size_t I, class T> class tuple_element;
    template <class T1, class T2> struct tuple_size<pair<T1, T2>>;
    template <size_t I, class T1, class T2> struct tuple_element<I, pair<T1, T2>>;
    template <class T1, class T2> struct tuple_element<0, pair<T1, T2>>;
    template <class T1, class T2> struct tuple_element<1, pair<T1, T2>>;
    
    […]
    
  2. Modify [pair.astuple] as indicated:

    tuple_element<0, pair<T1, T2>>::type
    

    -1- Value: The type T1.

    tuple_element<1, pair<T1, T2>>::type
    

    -2- Value: The type T2.

    tuple_element<I, pair<T1, T2>>::type
    

    -?- Requires: I < 2. The program is ill-formed if I is out of bounds.

    -?- Value: The type T1 if I == 0, otherwise the type T2.

  3. Modify [variant.helper] as indicated:

    variant_alternative<I, variant<Types...>>::type
    

    -4- Requires: I < sizeof...(Types). The program is ill-formed if I is out of bounds.

    -5- Value: The type TI.

Date: 2017-06-15.00:00:00

[ 2017-06-12, Moved to Tentatively Ready after 5 positive votes on c++std-lib ]

Date: 2017-06-10.00:00:00

Instantiating tuple_element with an out-of-bounds index requires a diagnostic for tuple and array, but not for pair. The specification requires an out-of-bounds index for pair to go to the base template instead, which is undefined.

Similarly, instantiating variant_alternative with an out-of-bounds index violates a requirement, but it is not required to be diagnosed.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2017-07-30 20:18:47adminsetstatus: voting -> wp
2017-06-26 13:46:20adminsetstatus: ready -> voting
2017-06-12 17:47:12adminsetmessages: + msg9248
2017-06-12 17:47:12adminsetstatus: new -> ready
2017-06-11 13:34:06adminsetmessages: + msg9246
2017-06-10 00:00:00admincreate