<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/106007>106007</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc++] is_swappable declares std::swap(), leading to linking errors when <utility> is not included
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          parport0
      </td>
    </tr>
</table>

<pre>
    The following example:

```
#include <exception>

class A {
 int mFd = -1;
public:
    A(A &&);
};

A::A(A &&other) {
 std::swap(mFd, other.mFd);
}
```

leads to a linking error:
```
undefined reference to `std::__1::enable_if<is_move_constructible<int>::value&&is_move_assignable<int>::value, void>::type std::__1::swap[abi:ne200000]<int>(int&, int&)'
```
when compiled with libc++.

That is because, as I could understand, there is an inclusion chain:
exception -> exception_ptr.h -> construct_at.h -> new -> type_traits -> is_swappable

and is_swappable declares std::swap as:
```
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __swap_result_t<_Tp> swap(_Tp& __x, _Tp& __y)
 _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value&& is_nothrow_move_assignable<_Tp>::value);
```

I would instead expect an error akin
```
error: no member named 'swap' in namespace 'std'
```
to appear if I am not including `<utility>` or `<algorithm>`.

I originally encountered this with [version r530567 coming from AOSP](https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/).

I also reproduced it with "trunk" clang on Godbolt:
https://godbolt.org/z/MKrrPdfja

For reference, it compiles successfully with GNU libstdc++, although I am not sure this is the correct behavior either.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVV2P4joP_jXhxhrUSSm0F1xAgX3Re3ZmtDtHmrsqTQzNbppUSQoz59cfJWX42GWlg1CbuHbsPH5sM-fkXiPOSbYk2WrEet8YO--Y7Yz1yag24mP-2iDsjFLmKPUe8J21n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