【发布时间】:2018-08-31 02:53:49
【问题描述】:
我有以下代码:
#include "type_traits"
#include <new>
void foo()
{
std::aligned_storage<10,alignof(long)> storage;
new (&storage) int(12);
}
我定义了一些存储空间(长度为 10 字节),我将 new 和 int 放置到该位置
gcc 7.3 给出以下警告:
<source>:10:10: warning: placement new constructing an object of type 'int' and size '4' in a region of type 'std::aligned_storage<10, 8>' and size '1' [-Wplacement-new=]
new (&storage) int(12);
如果我没有错,这个警告是不正确的。我在这里遗漏了什么还是这个警告是虚假的?
【问题讨论】:
标签: c++ alignment placement-new