Skip to content

Destructor of temporaries does not run #669

Open

Description

@lucic71
std::vector<Foo> v;
v.push_back(Foo(1)); // calls push_back(&&)

In C++ the sequence on Foo is:

  1. Construct the temporary
  2. Move construct Foo into push_back
  3. Call the destructor or Foo

3 is skipped in Rust


These patterns also don't call the destructor:

  1. Foo(1); - discarded constructor
  2. Foo(1).member;
  3. int defaulted(const Foo &f = Foo(42)) {}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions