禁用有关在派生类的复制构造函数内显式初始化基构造函数的警告
我正在使用启用了 -Wextra 的 g++ 版本 4.2.1。我包含来自库的标头,并且我不断收到有关库中某个类的以下警告,该警告是由 -Wextra 启用的(我已用 BaseClass 替换了该类的实际名称):
warning: base class ‘class BaseClass’ should be explicitly initialized in the copy constructor
我的问题是:我该如何禁用此警告?例如,-Wextra 还启用 -Wuninitialized,但我可以通过传递 -Wno-uninitialized 作为编译器标志来覆盖这个简单的操作。关于复制构造函数的警告是否有类似的内容?我无法在 g++ 手册页或任何其他论坛帖子中找到答案。
I'm using g++ version 4.2.1 with -Wextra enabled. I'm including a header from a library, and I keep getting the following warning about a class in the library, which is enabled by -Wextra (I've replaced the class's actual name with BaseClass):
warning: base class ‘class BaseClass’ should be explicitly initialized in the copy constructor
My question is: how can I disable this warning? For example, -Wextra also enables -Wuninitialized, but I can override that simple by passing -Wno-uninitialized as a compiler flag. Is there anything similar for the warning about the copy constructor? I wasn't able to find the answer in the g++ manpages or in any other forum posts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
给定:
此复制构造函数:
实际上意味着相同:
如果这确实是您的意思,则可以放入像上面这样的默认构造函数初始值设定项,并且警告将会消失。但编译器建议你实际上可能想要这个:
Given:
This copy constructor:
Really means the same as:
You can put in a default-constructor initializer like the above if that's really what you mean, and the warning will go away. But the compiler is suggesting that you might actually want this instead:
根据 http://gcc.gnu.org/onlinedocs/gcc/Warning-Options .html(搜索
Wextra
)是-Wextra
的固有部分,不能单独禁用(例如,它没有按其单独列出)自己的-W
选项)。看来您能做的最好的事情就是要么将库的使用隔离到禁用
-Wextra
的一个文件,要么根本不单独使用-Wextra
启用其所有组件(从该链接)。According to http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html (search for
Wextra
) that is an inherent part of-Wextra
and can't be disabled separately (e.g. it isn't listed separately by its own-W
option).It looks like the best you can do is either isolate the use of the library to one file on which you disable
-Wextra
or don't use-Wextra
at all and individually enable all its components (from that link).如果这不是一个真正的问题,并且您无法更改库(我猜您不能或者您已经这样做了),您可以使用 GCC 诊断编译指示。
If it's not a real problem, and you can't change the library (I guess you can't or you'd have done so), you can disable warnings temporarily using the GCC diagnostic pragma.