Skip to content

Commit c231506

Browse files
committed
[interop] mark C++ virtual functions as unavailable in Swift
They're not yet supported
1 parent c28031c commit c231506

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
@@ -3451,6 +3451,11 @@ namespace {
34513451

34523452
Decl *VisitCXXMethodDecl(const clang::CXXMethodDecl *decl) {
34533453
auto method = VisitFunctionDecl(decl);
3454+
if (decl->isVirtual() && isa_and_nonnull<ValueDecl>(method)) {
3455+
Impl.markUnavailable(
3456+
cast<ValueDecl>(method),
3457+
"virtual functions are not yet available in Swift");
3458+
}
34543459

34553460
if (Impl.SwiftContext.LangOpts.CxxInteropGettersSettersAsProperties ||
34563461
hasComputedPropertyAttr(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)