gpt4 book ai didi

c++ - 英特尔编译器无法使用 `attribute "__malloc_ _"does not take arguments` 进行 C++14 检查

转载 作者:行者123 更新时间:2023-12-05 04:44:15 30 4
gpt4 key购买 nike

我有以下代码(用于检测编译器是否支持C++14):

#include <memory>
#include <algorithm>

// Check the version language macro, but skip MSVC because
// MSVC reports 199711 even in MSVC 2017.
#if __cplusplus < 201402L && !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#error "insufficient support for C++14"
#endif

int main()
{
auto ptr = std::make_unique<int>(42);
constexpr int max = std::max(0, 1);
(void) ptr;
(void) max;
return 0;
}

当使用 g++(版本 11.2.1)和 g++ -std=c++14 test.cpp -o test 行编译时,它工作正常。当使用 intel 编译器(版本 2021.3.0(gcc 版本 11.2.1 兼容性))而不是使用 icpc -std=c++14 test.cpp -o test 编译它时,它失败了

In file included from /usr/include/c++/11/cwchar(44),
from /usr/include/c++/11/bits/postypes.h(40),
from /usr/include/c++/11/iosfwd(40),
from /usr/include/c++/11/bits/shared_ptr.h(52),
from /usr/include/c++/11/memory(77),
from test.cpp(1):
/usr/include/wchar.h(155): error: attribute "__malloc__" does not take arguments
__attribute_malloc__ __attr_dealloc_free;
^

In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(565): error: attribute "__malloc__" does not take arguments
__attr_dealloc_free;
^

In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(569): error: attribute "__malloc__" does not take arguments
__THROW __attr_dealloc (reallocarray, 1);
^

In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(797): error: attribute "__malloc__" does not take arguments
__attr_dealloc_free __wur;
^

compilation aborted for test.cpp (code 2)

这里到底出了什么问题,我该如何解决?

简短更新:看起来 CUDA 遇到了类似的问题,它可能与 glibc 2.34 有关:https://forums.developer.nvidia.com/t/cuda-11-5-samples-throw-multiple-error-attribute-malloc-does-not-take-arguments/192750/15

最佳答案

使用icpc 2021.4编译并执行共享代码,运行良好。

使用下面的命令来编译代码。icpc -std=c++14

下面是环境的详细信息。

操作系统:Ubuntu 18.04.3 LTS内核:Linux 4.15.0-76-generic

关于兼容性,请引用英特尔® C++ 编译器经典系统要求链接

https://software.intel.com/content/www/us/en/develop/articles/oneapi-c-compiler-system-requirements.html

关于c++ - 英特尔编译器无法使用 `attribute "__malloc_ _"does not take arguments` 进行 C++14 检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69404834/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com