将警告转换为错误 [英] Convert Warning to Error

查看:96
本文介绍了将警告转换为错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows中,VC ++具有一个漂亮的选项/We 进行转换特定的错误警告.同样,VC ++发出的每个警告都有一个警告编号,例如

In Windows, VC++ has a nifty option /We to convert a specific warning to error. Also every warning emitted by VC++ has a warning number for example

warning C4265: 'CFoo' : class has virtual functions, but destructor is not virtual

因此,使用/We可以轻松识别数字并添加编译器选项切换为/We4265

So it easy to identify the number and add a compiler option using the /We switch as /We4265

我检查了g ++文档并发现了类似的内容(我相信), -Werror = ,但文档中提到

I checked the g++ documentation and found something similar (I believe), -Werror=, but the documentation mentions

将指定的警告变为错误.

Make the specified warning into an error.

但是我的问题是,

给出编译器警告

/yada/yada/src/inc/module.h:580: warning: 'struct IFoo' has virtual functions but non-virtual destructor

如何使用-Werror编译器选项将其转换为错误?

How do I convert this to error using the -Werror compiler option?

推荐答案

这句话

附加了警告说明符;例如,-Werror=switch会将-Wswitch控制的警告变为错误.此开关采用否定形式,用于对特定警告取反-Werror;例如,即使-Werror生效,-Wno-error=switch也不会使-Wswitch警告成为错误.

The specifier for a warning is appended; for example -Werror=switch turns the warnings controlled by -Wswitch into errors. This switch takes a negative form, to be used to negate -Werror for specific warnings; for example -Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect.

我不确定100%,但是-Wdelete-non-virtual-dtor可能是有问题的警告,因此您需要-Werror=delete-non-virtual-dtor.

I'm not 100% sure, but -Wdelete-non-virtual-dtor might be the warning in question, so you'd need -Werror=delete-non-virtual-dtor.

这篇关于将警告转换为错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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