Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

UnsafeMutablePointer Not Calling Deinit of Generic Noncopyable Type in -ONone #85725

Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels
@Nobody1707

Description

@Nobody1707

Description

When callingdeinitialize(count:) on anUnsafeMutablePointer containing a generic non-copyable type, the deinit of said type is not called unless optimizations are enabled. Callingdeinitialize(count:) works properly when applied to anUnsafeMutablePointer containing either a non-generic non-copyable type or a copyable class type.

Reproduction

structUnique<T:~Copyable>:~Copyable{publicvarvalue:Tpublicinit(_ value:consumingT){print("Initializing Unique<\(T.self)>")self.value= value}deinit{print("Deinitializing Unique<\(T.self)>")}}structNumber:~Copyable{publicvarvalue:Intpublicinit(_ value:consumingInt){print("Initializing Number(\(copy value))")self.value= value}deinit{print("Deinitializing Number(\(value))")}}finalclassNoisy<T:~Copyable>{publicvarvalue:Tpublicinit(_ value:consumingT){self.value= valueprint("Initializng Noisy<\(T.self)>")}deinit{print("Deinitializing Noisy<\(T.self)>")}}do{leta= UnsafeMutablePointer<Unique<Int>>.allocate(capacity:1)  a.initialize(to:Unique(42))  a.deinitialize(count:1) // deinit should be called here.  a.deallocate()}do{leta= UnsafeMutablePointer<Number>.allocate(capacity:1)  a.initialize(to:Number(42))  a.deinitialize(count:1) // deinit is called here.  a.deallocate()}do{leta= UnsafeMutablePointer<Noisy<Int>>.allocate(capacity:1)  a.initialize(to:Noisy(42))  a.deinitialize(count:1) // deinit is called here.  a.deallocate()}

Expected behavior

Expected output at all optimization levels:

Initializing Unique<Int>Deinitializing Unique<Int>Initializing Number(42)Deinitializing Number(42)Initializng Noisy<Int>Deinitializing Noisy<Int>

Actual output at -ONone:

Initializing Unique<Int>Initializing Number(42)Deinitializing Number(42)Initializng Noisy<Int>Deinitializing Noisy<Int>

Environment

Swiftc 6.2 x86-64 Linux

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp