Skip to content

[libc++] std::equal cannot compare between ranges of element with and without volatile qualifier #59021

@alvinhochun

Description

@alvinhochun

The following code does not compile with libc++ from LLVM 15.

https://godbolt.org/z/6WaPjT8e4

int a[3] { 1, 2, 3 };
std::span<int> x(a, 3);
std::span<volatile int> y(a, 3);
std::equal(x.begin(), x.end(), y.begin(), y.end());
In file included from <source>:1:
In file included from /opt/compiler-explorer/clang-15.0.0/bin/../include/c++/v1/span:145:
In file included from /opt/compiler-explorer/clang-15.0.0/bin/../include/c++/v1/array:111:
/opt/compiler-explorer/clang-15.0.0/bin/../include/c++/v1/__algorithm/equal.h:28:10: error: no matching function for call to object of type 'std::__equal_to<int>'
    if (!__pred(*__first1, *__first2))
         ^~~~~~
/opt/compiler-explorer/clang-15.0.0/bin/../include/c++/v1/__algorithm/equal.h:59:17: note: in instantiation of function template specialization 'std::equal<std::__wrap_iter<int *>, std::__wrap_iter<volatile int *>, std::__equal_to<int> &>' requested here
  return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2,
                ^
/opt/compiler-explorer/clang-15.0.0/bin/../include/c++/v1/__algorithm/equal.h:77:17: note: in instantiation of function template specialization 'std::__equal<std::__equal_to<int>, std::__wrap_iter<int *>, std::__wrap_iter<volatile int *>>' requested here
  return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(),
                ^
<source>:8:16: note: in instantiation of function template specialization 'std::equal<std::__wrap_iter<int *>, std::__wrap_iter<volatile int *>>' requested here
    (void)std::equal(x.begin(), x.end(), y.begin(), y.end());
               ^
/opt/compiler-explorer/clang-15.0.0/bin/../include/c++/v1/__algorithm/comp.h:36:10: note: candidate function not viable: 2nd argument ('volatile int') would lose volatile qualifier
    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
         ^
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions