Код: Выделить всё
#include
int* pointers[3];
std::span s = pointers;
Код: Выделить всё
:4:29: error: no viable conversion from 'int *[3]' to 'std::span'
4 | std::span s = pointers;
| ^ ~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/span:230:7: note: candidate constructor not viable: no known conversion from 'int *[3]' to 'const span &' for 1st argument
230 | span(const span&) noexcept = default;
| ^ ~~~~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/span:192:2: note: candidate template ignored: could not match 'const int *' against 'int *'
192 | span(type_identity_t (&__arr)[_ArrayExtent]) noexcept
| ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/span:199:2: note: candidate template ignored: could not match 'array' against 'int *[3]'
199 | span(array& __arr) noexcept
| ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/span:206:2: note: candidate template ignored: could not match 'array' against 'int *[3]'
206 | span(const array& __arr) noexcept
| ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/span:218:2: note: candidate template ignored: constraints not satisfied [with _Range = int *(&)[3]]
218 | span(_Range&& __range)
| ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/span:213:8: note: because '!is_array_v' evaluated to false
213 | && (!is_array_v)
| ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/span:238:2: note: candidate template ignored: could not match 'span' against 'int *[3]'
238 | span(const span& __s) noexcept
| ^
У меня сложилось впечатление, что std::span можно сконструировать из диапазоны, если требуется только квалификационное преобразование (например, int* в const int * const). Какой компилятор здесь прав?
Это вполне вероятно просто особенность взаимодействия Clang/GCC, учитывая, что код также компилируется с -stdlib=libc++.
Подробнее здесь: https://stackoverflow.com/questions/792 ... -int-const