开发者

int(int(-2)/unsigned(2)) = 2147483647 no warning

I have a code similar to this:

template<typename Ta, typename Tb> Ta doStuff(Ta a, Tb b)
{
    ...
    return a/b;
}

As the title says such code would return wrong values with Ta=int Tb=unsigned.

Is there a way to get a warning 开发者_JAVA百科by g++ for this case ?


Yes. Use -Wsign-conversion option:

[nawaz@./]$ g++ filename.cpp -Wsign-conversion


Try with: g++ -Wall code.cpp -o output

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜