Skipping construction/destruction of stack allocated objects

Hello,

For performance reasons, I would like to provide a way to skip construction/destruction of objects that are stack allocated. Typically, C-style arrays of std::complex create an initialization loops that is almost always unnecessary.

I am thinking of providing an attribute((uninitialized)) that can be applied to an object declaration:

{
std::complex foo[64][64] attribute((uninitialized));
// does not need to generate a zeroinitializer loop here
somefunction(foo);
// does not need to generate a destructor loop here (std::complex don’t have one anyway)
}

Formally speaking, we won’t call constructors/destructors on those objects anymore. We would provide “uninitialized” memory in the same meaning as malloc/free.

Do you see this as a good idea? Do we already have a better way of achieving this?

I’m worried about the fact that for non-POD types it is not safe to ignore that attribute, which probably means using an attribute is not a good fit…

The standard way to allocate uninitialized storage in C++ is std::aligned_storage. The proposed extension doesn't really seem like an improvement over that.

-Eli

This seems like a better discussion to have on cfe-dev than on llvm-dev FWIW.

(I also happen to agree with Eli, but that’s somewhat irrelevant.)

Forwarding to cfe-dev as per Chandler’s suggestion.