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