mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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.
16 lines
595 B
Swift
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()
|