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
精彩评论