gpt4 book ai didi

c++ - [[maybe_unused]] 和构造函数

转载 作者:可可西里 更新时间:2023-11-01 17:37:44 29 4
gpt4 key购买 nike

尝试使用 gcc 8.2.1 和 clang 6.0.1 编译 sqlpp17 代码库是一种非常奇怪的体验。该代码将编译器推到了极限,同时我可能遇到了一些编译器错误。

从 GCC 文档中,[[maybe_unused]] 从版本 7 开始实现,但如果以这种方式使用:

struct foo {
foo([[maybe_unused]] bool thing1)
{
}
};

我遇到了这个特定的错误:

<source>:2:9: error: expected unqualified-id before '[' token
foo([[maybe_unused]] bool thing1)
^
<source>:2:9: error: expected ')' before '[' token
foo([[maybe_unused]] bool thing1)
~^
)
Compiler returned: 1

现在,我对 C++17 知之甚少,不知道这个错误是否正确,我知道 clang 6 可以很好地编译那部分(但在其他地方失败)。

那么,谁是对的,clang 还是 gcc? (clang 和 gcc 的标志都是 -std=gnu++17,由 CMake 生成)

最佳答案

这是 g++ 中的一个已知错误:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429 G++ 无法正确解析构造函数第一个参数的 [[maybe_unused]] 属性。

关于c++ - [[maybe_unused]] 和构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52263141/

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