|
42 | 42 | #include "swift/Basic/PrettyStackTrace.h" |
43 | 43 | #include "swift/Basic/Statistic.h" |
44 | 44 | #include "swift/Basic/StringExtras.h" |
| 45 | +#include "swift/Basic/Version.h" |
45 | 46 | #include "swift/ClangImporter/CXXMethodBridging.h" |
46 | 47 | #include "swift/ClangImporter/ClangImporterRequests.h" |
47 | 48 | #include "swift/ClangImporter/ClangModule.h" |
@@ -3744,33 +3745,39 @@ namespace { |
3744 | 3745 | Decl *VisitCXXMethodDecl(const clang::CXXMethodDecl *decl) { |
3745 | 3746 | auto method = VisitFunctionDecl(decl); |
3746 | 3747 | if (decl->isVirtual() && isa_and_nonnull<ValueDecl>(method)) { |
3747 | | - |
3748 | | - if (auto dc = method->getDeclContext(); |
3749 | | - !decl->isPure() && |
3750 | | - isa_and_nonnull<NominalTypeDecl>(dc->getAsDecl())) { |
3751 | | - |
3752 | | - // generates the __synthesizedVirtualCall_ C++ thunk |
3753 | | - clang::CXXMethodDecl *cxxThunk = synthesizeCxxVirtualMethod( |
3754 | | - *static_cast<ClangImporter *>( |
3755 | | - dc->getASTContext().getClangModuleLoader()), |
3756 | | - decl->getParent(), decl->getParent(), decl); |
3757 | | - |
3758 | | - // call the __synthesizedVirtualCall_ C++ thunk from a Swift thunk |
3759 | | - if (Decl *swiftThunk = |
3760 | | - cxxThunk ? VisitCXXMethodDecl(cxxThunk) : nullptr; |
3761 | | - isa_and_nonnull<FuncDecl>(swiftThunk)) { |
3762 | | - // synthesize the body of the Swift method to call the swiftThunk |
3763 | | - synthesizeForwardingThunkBody(cast<FuncDecl>(method), |
3764 | | - cast<FuncDecl>(swiftThunk)); |
3765 | | - return method; |
| 3748 | + if (Impl.isCxxInteropCompatVersionAtLeast( |
| 3749 | + version::getUpcomingCxxInteropCompatVersion())) { |
| 3750 | + if (auto dc = method->getDeclContext(); |
| 3751 | + !decl->isPure() && |
| 3752 | + isa_and_nonnull<NominalTypeDecl>(dc->getAsDecl())) { |
| 3753 | + |
| 3754 | + // generates the __synthesizedVirtualCall_ C++ thunk |
| 3755 | + clang::CXXMethodDecl *cxxThunk = synthesizeCxxVirtualMethod( |
| 3756 | + *static_cast<ClangImporter *>( |
| 3757 | + dc->getASTContext().getClangModuleLoader()), |
| 3758 | + decl->getParent(), decl->getParent(), decl); |
| 3759 | + |
| 3760 | + // call the __synthesizedVirtualCall_ C++ thunk from a Swift thunk |
| 3761 | + if (Decl *swiftThunk = |
| 3762 | + cxxThunk ? VisitCXXMethodDecl(cxxThunk) : nullptr; |
| 3763 | + isa_and_nonnull<FuncDecl>(swiftThunk)) { |
| 3764 | + // synthesize the body of the Swift method to call the swiftThunk |
| 3765 | + synthesizeForwardingThunkBody(cast<FuncDecl>(method), |
| 3766 | + cast<FuncDecl>(swiftThunk)); |
| 3767 | + return method; |
| 3768 | + } |
3766 | 3769 | } |
3767 | | - } |
3768 | 3770 |
|
3769 | | - Impl.markUnavailable( |
3770 | | - cast<ValueDecl>(method), |
3771 | | - decl->isPure() ? |
3772 | | - "virtual function is not available in Swift because it is pure" : |
3773 | | - "virtual function is not available in Swift"); |
| 3771 | + Impl.markUnavailable( |
| 3772 | + cast<ValueDecl>(method), |
| 3773 | + decl->isPure() ? "virtual function is not available in Swift " |
| 3774 | + "because it is pure" |
| 3775 | + : "virtual function is not available in Swift"); |
| 3776 | + } else { |
| 3777 | + Impl.markUnavailable( |
| 3778 | + cast<ValueDecl>(method), |
| 3779 | + "virtual functions are not yet available in Swift"); |
| 3780 | + } |
3774 | 3781 | } |
3775 | 3782 |
|
3776 | 3783 | if (Impl.SwiftContext.LangOpts.CxxInteropGettersSettersAsProperties || |
|
0 commit comments