Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ [maybe_unused]]和构造函数_C++_C++17 - Fatal编程技术网

C++ [maybe_unused]]和构造函数

C++ [maybe_unused]]和构造函数,c++,c++17,C++,C++17,尝试用gcc 8.2.1和clang 6.0.1编译sqlpp17代码库是一次非常奇怪的经历。代码将编译器推向了极限,同时我可能遇到了一些编译器错误 从GCC文档中,[[maybe_unused]]是从版本7开始实现的,但如果以这种方式使用: struct foo { foo([[maybe_unused]] bool thing1) { } }; 我遇到了这个特定的错误: :2:9:错误:在“[”标记之前应为非限定id foo([maybe_unused]]bool

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

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

struct foo {
    foo([[maybe_unused]] bool thing1)
    {
    }
};
我遇到了这个特定的错误:

:2:9:错误:在“[”标记之前应为非限定id
foo([maybe_unused]]bool thing1)
^
:2:9:错误:在“[”标记之前应为“)”
foo([maybe_unused]]bool thing1)
~^
)
返回的编译器:1
现在,我对C++17知之甚少,不知道这个错误是否正确,我知道Clang6可以很好地编译该部分(并且在其他地方失败)


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

这是g++中的一个已知错误:g++没有正确解析
[[可能未使用]]
构造函数第一个参数的属性。

我能做的最简单的例子:。简言之,gcc无法编译带有参数属性的构造函数。gcc bug,纯粹而简单:@Justin,仅针对第一个参数!bug仍然在那里设置@2019-Feb-7此语法有效(与gcc-8一起):
foo(bool thing1[[可能未使用]])
不幸的是,gcc 9.1中也有。@Algorys的解决方案可以工作,但在gcc 9.3中已修复。
<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