如何获得算术中被遗忘的警告? [英] How to obtain warning for forgotten cast in arithmetic?

查看:81
本文介绍了如何获得算术中被遗忘的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这种情况:

uint64_t add(uint32_t a, uint32_t b)
{
   return a + b; // programmer neglected (uint64_t) a + b.
}

我们如何让GCC(或任何其他编译器)的C或C ++前端警告这种情况:正在以立即扩大的狭窄类型进行操作?

How do we get the C or C++ front-end of GCC (or of any other compiler) to warn about this situation: that an operation is being done in a narrow type that is immediately widened?

我已经阅读了当前的GCC文档,并尝试了各种警告,例如 -Wconversion ,但是什么也没有.

I've read through the current GCC documentation, and tried various warnings like -Wconversion, but nothing.

推荐答案

我不知道GCC的标志会引起警告.Coverity静态分析器将发出 OVERFLOW_BEFORE_WIDEN 警告,因为这已被标记CERT标准.

I am not aware of a flag to GCC that will cause a warning. The Coverity static analyzer will issue an OVERFLOW_BEFORE_WIDEN warning as this is flagged in the CERT standards.

免责声明:我曾经为Coverity工作.

Disclaimer: I once worked for Coverity.

这篇关于如何获得算术中被遗忘的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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