Files
swift-mirror/test/Interop/Cxx/class/inheritance/virtual-methods-module-interface.swift
Puyan Lotfi 128064f31d [cxx-interop] Enable virtual function calling from Swift to C++
This is a forward-interop feature that wires up existing functionality for
synthesizing base class function calling to enable virtual function calling.
The general idea is to sythesize the pattern:

```
// C++ class:
struct S { virtual auto f() -> int { return 42; } };

// Swift User:
var s = S()
print("42: \(s.f())")

// Synthetized Swift Code:
extension S { func f() -> CInt { __synthesizedVirtualCall_f() } }

// Synthetized C/C++ Code:
auto __cxxVirtualCall_f(S *s) -> int { return s->f(); }
```

The idea here is to allow for the synthetized C++ bits from the Clang side to
handle the complexity of virtual function calling.
2023-12-04 01:55:30 -05:00

16 lines
595 B
Swift

// 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
// CHECK: struct Base {
// CHECK-NEXT: init()
// CHECK-NEXT: @available(*, unavailable, message: "virtual function is not available in Swift because it is pure")
// CHECK-NEXT: mutating func foo()
// CHECK: struct Derived<CInt> {
// CHECK-NEXT: init()
// CHECK-NEXT: mutating func foo()
// CHECK: }
// CHECK: struct VirtualNonAbstractBase {
// CHECK-NEXT: init()
// CHECK-NEXT: func nonAbstractMethod()