Non-copyable: compiler produces a copy of non-copyable value returned by pointer using 'unsafeAddress' accessor in a subscript #70047
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
noncopyable struct/enum
Feature → declarations: Noncopyable value type declarations
ownership
Feature: Ownership modifiers and semantics
Description
Using the
unsafeAddress
accessor in a subscript that returns a non-copyable type makes Swift copy the value when it's returned by a subscript get access that intends only to borrow the value. The following error is produced:This accessor is needed for C++ interop, to support use of non-copyable return references in accessors that get synthesized for an imported
operated []
.Reproduction
Expected behavior
The code should compile, as it should be okay to borrow the address value returned from the subscript accessor.
Environment
Swift main @:
commit 7680332 (origin/main, origin/HEAD)
Merge: 975519b 46c4da3
Date: Thu Nov 16 10:06:03 2023 -0800
Additional information
No response
The text was updated successfully, but these errors were encountered: