[[maybe_unused]]和构造函数 [英] [[maybe_unused]] and Constructors

查看:259
本文介绍了[[maybe_unused]]和构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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


现在,我对C ++ 17知之甚少,无法知道此错误是否正确,我知道clang 6可以很好地进行编译(并在其他地方失败)。

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).

所以,是正确的人,c语还是gcc? (对于lang和gcc,标志都是-std = gnu ++ 17,由CMake生成)

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

推荐答案

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

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.

这篇关于[[maybe_unused]]和构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆