[[maybe_unused]] and Constructors

我们两清 提交于 2020-04-10 07:37:04

问题


Trying to compile the sqlpp17 codebase with gcc 8.2.1 and clang 6.0.1 have been a really strange experience. The code pushes the compilers to the limits and I hit probably a few compiler bugs in the meantime.

From the GCC Docs, [[maybe_unused]] is implemented since version 7, but if used this way:

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

I hit this specific error:

<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

Now, I know too little about C++17 to know if this error is correct, I know that clang 6 compiles that part fine (and fails somewhere else).

So, who's right, clang or gcc? (flags are -std=gnu++17 for both clang and gcc, generated by CMake)


回答1:


This is a known bug in g++: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429 G++ doesn't parse correctly [[maybe_unused]] attribute for first argument of the constructor.



来源:https://stackoverflow.com/questions/52263141/maybe-unused-and-constructors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!