Skip to content

Commit 83d979c

Browse files
committed
[interop] mark C++ virtual functions as unavailable in Swift
They're not yet supported (cherry picked from commit c231506)
1 parent 9d9b964 commit 83d979c

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,11 @@ namespace {
34433443

34443444
Decl *VisitCXXMethodDecl(const clang::CXXMethodDecl *decl) {
34453445
auto method = VisitFunctionDecl(decl);
3446+
if (decl->isVirtual() && isa_and_nonnull<ValueDecl>(method)) {
3447+
Impl.markUnavailable(
3448+
cast<ValueDecl>(method),
3449+
"virtual functions are not yet available in Swift");
3450+
}
34463451

34473452
if (Impl.SwiftContext.LangOpts.CxxInteropGettersSettersAsProperties) {
34483453
CXXMethodBridging bridgingInfo(decl);

test/Interop/Cxx/class/inheritance/Inputs/virtual-methods.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ struct Unused : Base {
2727
};
2828

2929
using UnusedInt = Unused<int>;
30+
31+
struct VirtualNonAbstractBase {
32+
virtual void nonAbstractMethod() const;
33+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-ide-test -print-module -print-implicit-attrs -module-to-print=VirtualMethods -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2+
3+
// CHECK: struct Base {
4+
// CHECK-NEXT: init()
5+
// CHECK-NEXT: @available(*, unavailable, message: "virtual functions are not yet available in Swift")
6+
// CHECK-NEXT: mutating func foo()
7+
8+
// CHECK: struct Derived<Int32> {
9+
// CHECK: @available(*, unavailable, message: "virtual functions are not yet available in Swift")
10+
// CHECK: mutating func foo()
11+
// CHECK: }
12+
13+
// CHECK: struct VirtualNonAbstractBase {
14+
// CHECK: @available(*, unavailable, message: "virtual functions are not yet available in Swift")
15+
// CHECK: func nonAbstractMethod()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %S/Inputs -enable-experimental-cxx-interop
2+
3+
import VirtualMethods
4+
5+
VirtualNonAbstractBase().nonAbstractMethod() // expected-error {{'nonAbstractMethod()' is unavailable: virtual functions are not yet available in Swift}}

0 commit comments

Comments
 (0)