Skip to content

Conversation

egorzhdan
Copy link
Contributor

In libc++, std::any_cast is declared as a friend function of std::any.

ClangImporter was not correctly handling friend functions declared within structs within namespaces correctly.

rdar://147261941

@egorzhdan
Copy link
Contributor Author

This relies on #83752.

@egorzhdan egorzhdan force-pushed the egorzhdan/crash-any-cast branch from 23279b3 to f6e9964 Compare September 30, 2025 12:57
@egorzhdan egorzhdan force-pushed the egorzhdan/crash-any-cast branch from f6e9964 to 189e461 Compare October 7, 2025 10:45
@Xazax-hun
Copy link
Contributor

@swift-ci please smoke test

@swiftlang swiftlang deleted a comment from egorzhdan Oct 8, 2025
@egorzhdan egorzhdan force-pushed the egorzhdan/crash-any-cast branch from 189e461 to 8f0aef2 Compare October 9, 2025 11:53
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

<any> in libc++ declares this overload of any_cast:

template <class _ValueType>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any const& __v)

This is the overload that Swift picks and is able to use.

Microsoft STL, however, does not have this overload. The overloads there return remove_cv_t<T> which we aren't able to import yet.

In libc++, `std::any_cast` is declared as a friend function of `std::any`.

ClangImporter was not correctly handling friend functions declared within structs within namespaces correctly.

rdar://147261941
@egorzhdan egorzhdan force-pushed the egorzhdan/crash-any-cast branch from 8f0aef2 to 18c5e23 Compare October 9, 2025 12:10
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan egorzhdan merged commit 1803d3e into swiftlang:main Oct 10, 2025
3 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/crash-any-cast branch October 10, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ interop Feature: Interoperability with C++

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants