Skip to content

Undefined behavior: let initializers admit accessing uninitialized memory in some cases. #85028

@jamieQ

Description

@jamieQ

Description

possibly related-to and (certainly) inspired-by the issue reported here: #84909, there are cases in which let bindings can access and store references to uninitialized memory. this essentially seems like the same problem that was fixed in #37935, but for lets (with temporary allocations) rather than vars.

Reproduction

func f() {
  let selfRef: Any = { selfRef }()
  print("self ref: \(selfRef)") // crashes with a bad pointer dereference or ASAN failure at runtime
}

Expected behavior

capturing 'forward declared' let bindings should be diagnosed and rejected at compile time as is the case with var bindings.

Environment

Swift version 6.2 (swift-6.2-RELEASE)
Target: x86_64-unknown-linux-gnu

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