[[maybe_unused]]和构造函数

Tom*_*ava 9 c++ c++17

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

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

struct foo {
    foo([[maybe_unused]] bool thing1)
    {
    }
};
Run Code Online (Sandbox Code Playgroud)

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

<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
Run Code Online (Sandbox Code Playgroud)

现在,我对C++ 17知之甚少,知道这个错误是否正确,我知道clang 6编译该部分很好(并且在其他地方失败).

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

Ser*_*eyA 12

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

  • 这个错误仍然存​​在于@ 2019-Feb-7 (2认同)
  • 此语法有效(与gcc-8一起使用):`foo(bool something1 [[maybe_unused]])` (2认同)