Paolo Carlini wrote:
[...]
Let's wait a bit more for other opinions, say one day or two, then I will start the actual work. As far as I can see, other compilers do not warn in such cases, and adding casts (*) isn't the cleanest practice in the world, thus my caution...

FYI: HP aCC warns for some but not all of these types of lossy
initializations. For example, a double to int conversion emits
a warning but ptrdiff_t to size_t or other signed to unsigned
conversions do not, probably because they're so common. I find
this behavior useful.

Martin

$ cat t.cpp && aCC -AA -V -c +w t.cpp
int foo (double d)
{
    const int i = d;
    return i;
}

aCC: HP ANSI C++ B3910B A.03.70
Warning (suggestion) 819: "t.cpp", line 3 # Initialization of type 'int' with 'double' may result in truncation of value.
        const int i = d;
                      ^
Warning (suggestion) 818: "t.cpp", line 3 # Type 'double' is larger than type 'int', truncation in value may result.
        const int i = d;
                      ^

Reply via email to