Skip to content

[Interop] Test APINotes support for noncopyable types with SwiftDestroyOp #83671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/Interop/C/struct/Inputs/NoncopyableStructs.apinotes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Name: NoncopyableStructs
Tags:
- Name: NonCopyableWithAPINotesDeinit
SwiftCopyable: false
SwiftDestroyOp: freeNonCopyableWithAPINotesDeinit
5 changes: 5 additions & 0 deletions test/Interop/C/struct/Inputs/noncopyable-struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ typedef struct SWIFT_NONCOPYABLE_WITH_DESTROY(freeNonCopyableWithDeinit) NonCopy
void *storage;
} NonCopyableWithDeinit;

typedef struct NonCopyableWithAPINotesDeinit {
void *storage;
} NonCopyableWithAPINotesDeinit;

typedef struct __attribute__((swift_attr("destroy:freeCopyableType"))) CopyableType {
void *storage;
} CopyableType;
Expand All @@ -29,6 +33,7 @@ extern "C" {
#endif

void freeNonCopyableWithDeinit(NonCopyableWithDeinit ncd);
void freeNonCopyableWithAPINotesDeinit(NonCopyableWithAPINotesDeinit ncd);
void freeCopyableType(CopyableType ct);


Expand Down
6 changes: 6 additions & 0 deletions test/Interop/C/struct/noncopyable_structs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ func testNC() {
let nc = NonCopyable() // expected-error{{'nc' consumed more than once}}
consumeNC(nc) // expected-note{{consumed here}}

let ncAPI = NonCopyableWithAPINotesDeinit() // expected-error{{consumed more than once}}
consumeNCAPI(ncAPI) // expected-note{{consumed here}}

#if ERRORS
consumeNC(nc) // expected-note{{consumed again here}}
consumeNCAPI(ncAPI) // expected-note{{consumed again here}}
#endif
}

func consumeNCAPI(_ nc: consuming NonCopyableWithAPINotesDeinit) { }

func consumeNCWithDeinit(_ nc: consuming NonCopyableWithDeinit) { }

func testNCWithDeinit() {
Expand Down