The most paranoid way is
::new ((void *)::std::addressof(storage)) T(a, b, c);
Explanation:
::std::addressof
guards against overloaded unaryoperator&
onstorage
, which is technically allowed by the standard. (Though no sane implementation would do it.) The::std
guards against any non-top-level namespaces (or classes) calledstd
that might be in scope.(void *)
(which in this case is the equivalent of astatic_cast
) ensures that you call the placementoperator new
taking avoid *
rather than something else likedecltype(storage) *
.::new
skips any class-specific placementoperator new
s, ensuring that the call goes to the global one.
Together, this guarantees that the call goes to the library placement operator new
taking a void *
, and that the T
is constructed at where storage
is.
In most sane programs, though,
new (&storage) T(a,b,c);
should be sufficient.