我试图编译一个C++代码,使用过对齐的变量.如果我try 编译以下代码(MWE)
#include <new>
#include <iostream>
int main()
{
alignas(32) double *r = new (std::align_val_t{32}) double[3];
std::cout << "alignof(r) is " << alignof(r) << '\n';
return 0;
}
如果我使用icpx
或g++
(在所有情况下,标志-std=c++17
都被赋予编译器),那么一切都会顺利运行.然而,在使用英特尔icpc
编译时,我遇到了以下错误
mwe.cpp(6): error: no instance of overloaded "operator new[]" matches the argument list
argument types are: (unsigned long, std::align_val_t)
alignas(32) double *r = new (std::align_val_t{32}) double[3];
^
/usr/include/c++/9/new(175): note: this candidate was rejected because arguments do not match
_GLIBCXX_NODISCARD inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
^
/usr/include/c++/9/new(141): note: this candidate was rejected because arguments do not match
_GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
^
/usr/include/c++/9/new(127): note: this candidate was rejected because mismatch in count of arguments
_GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
^
mwe.cpp(7): warning #3464: the standard "alignof" operator does not accept an expression argument (use a type instead)
std::cout << "alignof(r) is " << alignof(r) << '\n';
^
compilation aborted for mwe.cpp (code 2)
我不明白错误是什么.