llvm / llvm/llvm-project

[libc++] unqualified calls to std::swap in __split_buffer::__swap_layouts cause ambiguous call when used with boost::math

Open Beginner friendly
#212,854 0 comments 1 reaction 0 assignees View on GitHub
libc++
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The unqualified calls to `std::swap` introduced to __split_buffer::__swap_layouts in https://github.com/llvm/llvm-project/commit/8c2c816cf746d70b2623412c81c50e8d96d1c13a can cause ambiguous calls when used with boost datatypes, such as in this example:
```c++
#include
#include

int main() {
std::vector vector;
vector.push_back(boost::math::normal(0, 1));
return 0;
}
```

Attempting to compile this results in this error:
```
In file included from test.cc:1:
In file included from /usr/include/boost/math/distributions.hpp:15:
In file included from /usr/include/boost/math/distributions/arcsine.hpp:37:
In file included from /usr/include/boost/math/distributions/detail/common_error_handling.hpp:16:
In file included from /usr/include/boost/math/special_functions/fpclassify.hpp:20:
In file included from /usr/include/boost/math/special_functions/math_fwd.hpp:107:
In file included from /usr/include/c++/v1/vector:314:
In file included from /usr/include/c++/v1/__vector/vector.h:49:
/usr/include/c++/v1/__split_buffer:195:5: error: call to 'swap' is ambiguous
195 | swap(__begin_, __begin);
| ^~~~
/usr/include/c++/v1/__split_buffer:215:5: note: in instantiation of member function 'std::__split_buffer_pointer_layout,
std::allocator>, std::__split_buffer_pointer_layout>, boost::math::normal_distribution<>,
std::allocator>>::__swap_layouts' requested here
215 | __swap_layouts(__first, __last, __capacity);
| ^
/usr/include/c++/v1/__vector/layout.h:409:12: note: in instantiation of member function 'std::__split_buffer_pointer_layout,
std::allocator>, std::__split_buffer_pointer_layout>, boost::math::normal_distribution<>,
std::allocator>>::__relocate' requested here
409 | __buffer.__relocate(__begin_, __end_, __capacity_);
| ^
/usr/include/c++/v1/__vector/vector.h:1053:13: note: in instantiation of member function 'std::__vector_layout,
std::allocator>>::__relocate' requested here
1053 | __layout_.__relocate(__v);
| ^
/usr/include/c++/v1/__vector/vector.h:1086:21: note: in instantiation of function template specialization
'std::vector>::__emplace_back_slow_path>' requested here
1086 | [&] { __end = __emplace_back_slow_path(std::forward<_Args>(__args)...); });
| ^
/usr/include/c++/v1/__vector/vector.h:466:90: note: in instantiation of function template specialization
'std::vector>::emplace_back>' requested here
466 | _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x) { emplace_back(std::move(__x)); }
| ^
test.cc:6:10: note: in instantiation of member function 'std::vector>::push_back' requested here
6 | vector.push_back(boost::math::normal(0, 1));
| ^
/usr/include/c++/v1/__utility/swap.h:41:81: note: candidate function [with _Tp = boost::math::normal_distribution<> *]
41 | inline _LIBCPP_HIDE_FROM_ABI __swap_result_t<_Tp> _LIBCPP_CONSTEXPR_SINCE_CXX20 swap(_Tp& __x, _Tp& __y)
| ^
/usr/include/boost/math/tools/utility.hpp:31:6: note: candidate function [with T = boost::math::normal_distribution<> *]
31 | void swap BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (T& a, T& b)
| ^
```

Simply making those three calls fully qualified fixes this issue.

Contributor guide

Open the contributing guide

Research direction

Start with libc++'s __split_buffer::__swap_layouts and reproduce the ambiguity using the Boost.Math vector example from test.cc. Inspect the three swap calls implicated by the diagnostic, then verify that the example compiles successfully after the calls are fully qualified.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.