Issue 175091
Summary [libc++] flat_set compilation fails with "_Ops::advance is ambiguous"
Labels libc++
Assignees
Reporter halbi2
    https://godbolt.org/z/Y4Gbc4Wh7

Maybe related to #119017 #171371. I cannot see what is wrong with this code that it should not compile on libc++. It does compile on libstdc++. The `operator==` is required.

```
#include <flat_set>

struct T {
    T(const auto&);
 friend bool operator==(T,T);
};

struct Comp {
    bool operator()(T,T) const;
};

int main() {
    std::flat_set<T, Comp> x = {0};
}
```
The error message is as follows
```
In file included from <source>:1:
In file included from /cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/flat_set:595:
In file included from /cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_multiset.h:17:
In file included from /cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/ranges_inplace_merge.h:12:
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/inplace_merge.h:167:7: error: call to object of type 'const __advance' is ambiguous
  167 | _Ops::advance(__m2, __len21);
      | ^~~~~~~~~~~~~
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/inplace_merge.h:215:15: note: in instantiation of function template specialization 'std::__inplace_merge<std::_RangeAlgPolicy, Comp &, std::__wrap_iter<T *>>' requested here
  215 |   return std::__inplace_merge<_AlgPolicy>(
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/ranges_inplace_merge.h:47:10: note: in instantiation of function template specialization 'std::__inplace_merge<std::_RangeAlgPolicy, std::__wrap_iter<T *>, Comp &>' requested here
   47 |     std::__inplace_merge<_RangeAlgPolicy>(
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_set.h:707:7: note: in instantiation of function template specialization 'std::ranges::__inplace_merge::operator()<std::__wrap_iter<T *>, std::__wrap_iter<T *>, Comp, std::identity>' requested here
  707 | ranges::inplace_merge(__keys_.begin(), __keys_.begin() + __old_size, __keys_.end(), __compare_);
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_set.h:446:5: note: in instantiation of function template specialization 'std::flat_set<T, Comp>::__append_sort_merge_unique<false, const T *, const T *>' requested here
  446 |     __append_sort_merge_unique</*WasSorted = */ false>(std::move(__first), std::move(__last));
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_set.h:146:5: note: in instantiation of function template specialization 'std::flat_set<T, Comp>::insert<const T *>' requested here
  146 |     insert(__first, __last);
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_set.h:170:9: note: in instantiation of function template specialization 'std::flat_set<T, Comp>::flat_set<const T *>' requested here
  170 |       : flat_set(__il.begin(), __il.end(), __comp) {}
      | ^
<source>:13:32: note: in instantiation of member function 'std::flat_set<T, Comp>::flat_set' requested here
   13 | std::flat_set<T, Comp> x = {0};
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__iterator/advance.h:99:40: note: candidate function [with _Ip = std::__wrap_iter<T *>]
   99 | _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Ip& __i, iter_difference_t<_Ip> __n) const {
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__iterator/advance.h:123:40: note: candidate function [with _Ip = std::__wrap_iter<T *>, _Sp = long]
 123 |   _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Ip& __i, _Sp __bound_sentinel) const {
      | ^
In file included from <source>:1:
In file included from /cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/flat_set:595:
In file included from /cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_multiset.h:13:
In file included from /cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/equal_range.h:17:
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/upper_bound.h:41:23: error: call to object of type 'const __next' is ambiguous
   41 |     auto __mid      = _IterOps<_AlgPolicy>::next(__first, __half_len);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/inplace_merge.h:168:22: note: in instantiation of function template specialization 'std::__upper_bound<std::_RangeAlgPolicy, Comp &, std::__wrap_iter<T *>, std::__wrap_iter<T *>, T, std::__identity>' requested here
  168 | __m1    = std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, std::__identity());
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/inplace_merge.h:215:15: note: in instantiation of function template specialization 'std::__inplace_merge<std::_RangeAlgPolicy, Comp &, std::__wrap_iter<T *>>' requested here
  215 |   return std::__inplace_merge<_AlgPolicy>(
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__algorithm/ranges_inplace_merge.h:47:10: note: in instantiation of function template specialization 'std::__inplace_merge<std::_RangeAlgPolicy, std::__wrap_iter<T *>, Comp &>' requested here
   47 |     std::__inplace_merge<_RangeAlgPolicy>(
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_set.h:707:7: note: in instantiation of function template specialization 'std::ranges::__inplace_merge::operator()<std::__wrap_iter<T *>, std::__wrap_iter<T *>, Comp, std::identity>' requested here
  707 | ranges::inplace_merge(__keys_.begin(), __keys_.begin() + __old_size, __keys_.end(), __compare_);
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_set.h:446:5: note: in instantiation of function template specialization 'std::flat_set<T, Comp>::__append_sort_merge_unique<false, const T *, const T *>' requested here
  446 |     __append_sort_merge_unique</*WasSorted = */ false>(std::move(__first), std::move(__last));
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_set.h:146:5: note: in instantiation of function template specialization 'std::flat_set<T, Comp>::insert<const T *>' requested here
  146 |     insert(__first, __last);
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__flat_set/flat_set.h:170:9: note: in instantiation of function template specialization 'std::flat_set<T, Comp>::flat_set<const T *>' requested here
  170 |       : flat_set(__il.begin(), __il.end(), __comp) {}
      | ^
<source>:13:32: note: in instantiation of member function 'std::flat_set<T, Comp>::flat_set' requested here
   13 | std::flat_set<T, Comp> x = {0};
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__iterator/next.h:46:53: note: candidate function [with _Ip = std::__wrap_iter<T *>]
   46 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
      | ^
/cefs/2b/2bbdb44660c4349b94019939_clang-trunk-20260108/bin/../include/c++/v1/__iterator/next.h:52:53: note: candidate function [with _Ip = std::__wrap_iter<T *>, _Sp = long]
 52 |   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const {
      | ^
2 errors generated.
Compiler returned: 1
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to