Files
swift-mirror/test/Interop/Cxx/objc-correctness/at-objc-api-using-non-trivial-cxx.swift
Alex Lorenz c2e15d6472 [cxx-interop] disallow use of non-trivial C++ types in @objc declarations
Even though such types can technically be represented in C++, Swift's @objc support does not support them

rdar://114163485
2023-10-18 17:49:13 -07:00

61 lines
1.3 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -typecheck -I %t/Inputs -cxx-interoperability-mode=default -verify %t/test.swift
// REQUIRES: objc_interop
//--- Inputs/header.h
class Trivial {
public:
int x;
};
class NonTrivial {
public:
NonTrivial(const NonTrivial &other) : x(other.x) {}
~NonTrivial() { }
private:
int x;
};
struct NonTrivialDestrOnly {
~NonTrivialDestrOnly() { }
private:
int x;
};
//--- Inputs/module.modulemap
module NonTrivial {
header "header.h"
export *
}
//--- test.swift
import Foundation
import NonTrivial
@objc
class ObjCObject: NSObject {
@objc var prop: NonTrivial // expected-error {{property cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-1 {{non-trivial C++ classes cannot be represented in Objective-C}}
@objc var trivProp: Trivial
override init() { fatalError() }
@objc func getNonTrivial() -> NonTrivialDestrOnly { // expected-error {{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
// expected-note@-1 {{non-trivial C++ classes cannot be represented in Objective-C}}
fatalError()
}
@objc func getTrivial() -> Trivial {
return Trivial(x: 11)
}
}