Skip to content

[CIR] Array elements are destructed in the wrong order #1759

@andykaylor

Description

@andykaylor

If I create an automatic variable with an array of objects that require a destructor call, the elements are incorrect destructed from first to last. They should be destructed in reverse order.

Reproducer:

#include <iostream>

int count = 0;

struct S {
  int i;
  S() { 
    i = count++;
    std::cout << "S ctor, i = " << i << "\n";
  }
  ~S() {
    std::cout << "S dtor, i = " << i << "\n";
  }
};

int main() {
  S s[10];
  return 0;
}

https://godbolt.org/z/3xbbTGM6M

(Note: As of the time I submitted this issue, only one element gets constructed or destructed. Hopefully, the link above will show the problem after #1758 is merged.)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions