#include <iostream>
#include <new>
class Test
{
public:
Test() = delete;
Test(const Test&) = delete;
Test(Test&&) = delete;
Test& operator=(const Test&) = delete;
Test& operator=(Test&&) = delete;
Test(int a, int b) : a_(a), b_(b) { std::cout << "ctor: " << a_ << ' ' << b_ << '\n'; }
virtual ~Test() { std::cout << "dtor: " << a_ << ' ' << b_ << '\n'; }
int a_;
int b_;
};
class B
{
public:
B()
{
::new (test_array_storage + 0 * sizeof(Test)) Test(1, 2);
::new (test_array_storage + 1 * sizeof(Test)) Test(3, 4);
}
B(const B&) = delete;
B(B&&) = delete;
B& operator=(const B&) = delete;
B& operator=(B&&) = delete;
~B()
{
reinterpret_cast<Test*>(test_array_storage + 1 * sizeof(Test))->~Test();
reinterpret_cast<Test*>(test_array_storage + 0 * sizeof(Test))->~Test();
}
private:
alignas(Test) unsigned char test_array_storage[sizeof(Test) * 2];
};
int main()
{
B b;
Test test[2] = {{1, 2}, {3, 4}};
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bmV3PgoKY2xhc3MgVGVzdAp7CnB1YmxpYzoKICAgIFRlc3QoKSA9IGRlbGV0ZTsKCiAgICBUZXN0KGNvbnN0IFRlc3QmKSA9IGRlbGV0ZTsKICAgIFRlc3QoVGVzdCYmKSA9IGRlbGV0ZTsKICAgIFRlc3QmIG9wZXJhdG9yPShjb25zdCBUZXN0JikgPSBkZWxldGU7CiAgICBUZXN0JiBvcGVyYXRvcj0oVGVzdCYmKSA9IGRlbGV0ZTsKCiAgICBUZXN0KGludCBhLCBpbnQgYikgOiBhXyhhKSwgYl8oYikgeyBzdGQ6OmNvdXQgPDwgImN0b3I6ICIgPDwgYV8gPDwgJyAnIDw8IGJfIDw8ICdcbic7IH0KICAgIHZpcnR1YWwgflRlc3QoKSB7IHN0ZDo6Y291dCA8PCAiZHRvcjogIiA8PCBhXyA8PCAnICcgPDwgYl8gPDwgJ1xuJzsgfQoKICAgIGludCBhXzsKICAgIGludCBiXzsKfTsKCmNsYXN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