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

    <tr>
        <th>Summary</th>
        <td>
            [libc++] std::expected does not work properly with std::any
        </td>
    </tr>

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

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

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

<pre>
    Compilation errors will occur when using types like `std::expected<std::any, int>`, but both gcc and msvc can compile normally.

for example: https://godbolt.org/z/nYaEafoah
```c++
#include <expected>
#include <any>
#include <memory>

int main() {
    auto core = std::make_shared<std::expected<std::any, int>>();
    return 0;
}
```

output:
```
In file included from <source>:1:
In file included from /opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/expected:44:
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__expected/expected.h:540:14: error: satisfaction of constraint '__can_convert<_Up, _OtherErr, const _Up &, const _OtherErr &>::value' depends on itself
  540 |     requires __can_convert<_Up, _OtherErr, const _Up&, const _OtherErr&>::value
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__expected/expected.h:540:14: note: while substituting template arguments into constraint expression here
  540 |     requires __can_convert<_Up, _OtherErr, const _Up&, const _OtherErr&>::value
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__type_traits/is_copy_constructible.h:25:38: note: while checking constraint satisfaction for template 'expected<std::any, int>' required here
   25 |     : public integral_constant<bool, __is_constructible(_Tp, __add_lvalue_reference_t<typename add_const<_Tp>::type>)> {
      | ^~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__type_traits/is_copy_constructible.h:25:38: note: while substituting deduced template arguments into function template 'expected' [with _Up = std::any, _OtherErr = int]
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/any:211:35: note: in instantiation of template class 'std::is_copy_constructible<std::expected<std::any, int>>' requested here
 211 |                                   is_copy_constructible<_Tp>::value> >
      | ^
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/any:460:6: note: in instantiation of default argument for 'any<std::expected<std::any, int> &, decay_t<expected<any, int> &>>' required here
  460 | any::any(_ValueType&& __v) : __h_(nullptr) {
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  461 | __any_imp::_Handler<_Tp>::__create(*this, std::forward<_ValueType>(__v));
 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 462 | }
      | ~
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__type_traits/is_constructible.h:22:103: note: (skipping 11 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
   22 | struct _LIBCPP_TEMPLATE_VIS is_constructible : public integral_constant<bool, __is_constructible(_Tp, _Args...)> {};
      | ^
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__memory/shared_ptr.h:306:10: note: in instantiation of template class 'std::__compressed_pair<std::allocator<std::expected<std::any, int>>, std::expected<std::any, int>>' requested here
  306 |   struct _ALIGNAS_TYPE(_CompressedPair) _Storage {
      | ^
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__config:617:30: note: expanded from macro '_ALIGNAS_TYPE'
  617 | #    define _ALIGNAS_TYPE(x) alignas(x)
      | ^
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__memory/shared_ptr.h:325:17: note: in instantiation of member class 'std::__shared_ptr_emplace<std::expected<std::any, int>, std::allocator<std::expected<std::any, int>>>::_Storage' requested here
 325 |   static_assert(_LIBCPP_ALIGNOF(_Storage) == _LIBCPP_ALIGNOF(_CompressedPair), "");
      | ^
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__config:616:34: note: expanded from macro '_LIBCPP_ALIGNOF'
  616 | #    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
      | ^
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__memory/shared_ptr.h:823:51: note: in instantiation of template class 'std::__shared_ptr_emplace<std::expected<std::any, int>, std::allocator<std::expected<std::any, int>>>' requested here
  823 | ::new ((void*)std::addressof(*__guard.__get())) _ControlBlock(__a, std::forward<_Args>(__args)...);
      | ^
/opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__memory/shared_ptr.h:831:15: note: in instantiation of function template specialization 'std::allocate_shared<std::expected<std::any, int>, std::allocator<std::expected<std::any, int>>, void>' requested here
  831 |   return std::allocate_shared<_Tp>(allocator<_Tp>(), std::forward<_Args>(__args)...);
      |               ^
<source>:6:22: note: in instantiation of function template specialization 'std::make_shared<std::expected<std::any, int>, void>' requested here
 6 |     auto core = std::make_shared<std::expected<std::any, int>>();
 |                      ^
1 error generated.
Compiler returned: 1
```

Another example: https://godbolt.org/z/sfqPT7T1W

```c++
#include <expected>
#include <any>
#include <utility>

static std::expected<std::any, int> a;

std::expected<std::any, int> test() {
    return std::move(a);
}

int main() {
    test();
 return 0;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWU1z6jjW_jViowply2DMgoUD4e1bdd_pVN10T_VKJeRj0ESW3JKcj17Mb5-SbIwJJLm5uenJYigqAaOPc87z6DlHErNWbBXAAk0v0XQ1Yo3babP4hfFbMHK00cXjYqmrWkjmhFYYjNHG4nshJdacNwbf70Dhxgq1xe6xBouluAWM0si6AiU5SnJ4qIE7KFCy7J8x9YjIEgvlUHKF0sh_2TQOb7Tb4S3nmKkCV_aOY84U5sECwEqbikn5OEbRCkV5-7fUBsMDq2oJKMnxzrna-knIGpH1VhcbLd1Ymy0i678QW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