我可以将特定警告视为错误吗? [英] Can I treat a specific warning as an error?

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

问题描述

以下是我在学生代码中有时看到的模式的简化版本:

The following is a simplified version of a pattern I sometimes see in my students' code:

bool foobar(int a, int b)
{
    if (a < b) return true;
}

当然,真正的代码更复杂。 Visual Studio报告警告C4715(不是所有控制路径都返回值),我想将所有警告C4715视为错误。这是可能的吗?

The real code is more complicated, of course. Visual Studio reports a warning C4715 (not all control paths return a value), and I would like to treat all warnings C4715 as errors. Is that possible?

推荐答案

这应该做的诀窍: #pragma warning(error:4715) / code>。

/ we4715 命令行选项(请参见 / w / W0 / W1 / W2 / W3 / W4 / w1 / w2 / w3 / w4 / / wd,/ we,/ wo,/ Wv,/ WX(警告级别)(由Tom Sigerdas提供)。

This should do the trick: #pragma warning (error: 4715).
Or the /we4715 command line option (see /w, /W0, /W1, /W2, /W3, /W4, /w1, /w2, /w3, /w4, /Wall, /wd, /we, /wo, /Wv, /WX (Warning Level) (courtesy of Tom Sigerdas)).

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

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