Title
std::span<volatile T, E> is made ill-formed by P2278R4 when T is a normal class type
Status
new
Section
[span.overview]
Submitter
Jiang An

Created on 2022-11-06.00:00:00 last changed 17 months ago

Messages

Date: 2022-11-12.01:08:30

[ Kona 2022-11-12; Set priority to 2 ]

Date: 2022-11-06.00:00:00

This issue is discovered when implementing the span part of P2278R4 in MSVC STL.

P2278R4 added the const_iterator member type to std::span, which required its iterator type to model std::input_iterator (same for const_reverse_iterator and reverse_iterator).

However, when element_type is volatile T and T is a class type, the iterator type generally fails to satisfy input_iterator, because:

  1. input_iterator<iterator> requires indirectly_readable<iterator>;

  2. indirectly_readable<iterator> requires common_reference_with<iterator_reference_t<iterator>&&, iterator_rvalue_reference_t<iterator>&&>, that is common_reference_with<volatile T&, volatile T&&>;

  3. common_reference_t<volatile T&, volatile T&&> is T (which is problematic), and thus common_reference_with<volatile T&, volatile T&&> requires both convertible_to<volatile T&, T> and convertible_to<volatile T&&, T>;

  4. However, the class type T generally doesn't have constructors from volatile T or const volatile T glvalues, and thus neither convertible_to<volatile T&, T> and convertible_to<volatile T&&, T> is satisfied.

Ideally, span should not require any form of construction of element_type. Although usages of class types provided by the standard library via volatile glvalues are generally not supported, I think span<volatile T, E> is still useful for some user-defined class type T, and thus shouldn't be forbidden.

History
Date User Action Args
2022-11-12 01:08:30adminsetmessages: + msg13037
2022-11-06 00:00:00admincreate