[Bug c++/60342] New: -Wsign-conversion ignores explicit conversion
woodroof at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Feb 26 08:54:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60342
Bug ID: 60342
Summary: -Wsign-conversion ignores explicit conversion
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: woodroof at gmail dot com
Simple example:
#include <cstddef>
#include <limits>
int main()
{
int int_value;
if (std::numeric_limits<size_t>::max() -
static_cast<size_t>(int_value))
{
}
}
Result:
1.cpp: In function ‘int main()’:
1.cpp:7:72: warning: conversion to ‘long unsigned int’ from ‘int’ may change
the sign of the result [-Wsign-conversion]
if (std::numeric_limits<size_t>::max() - static_cast<size_t>(int_value))
^
If I change numeric_limits::max to any size_t variable, warning will not be
generated. There is no warning also if I used usigned instead of size_t.
Possible the same problem as in bug 49626, but there is no conversion to a
wider type.
More information about the Gcc-bugs
mailing list