Yes, I agree with you on this. These scenarios shouldn't trigger
warnings in _default_ compiler warning level. So my question should be
about 64-bit porting only, ie. it would be better for me if GCC
supported some thing like -Wporting that includes porting related
warnings, such as this assign-long-to-int thing.
That's a special case. Sun CC generates a number of warnings in
64 bit mode, when it thinks that the semantics of the program
might be different than they would be in 32 bit mode. I've not
found them very useful, however.
I think overflow-checking and warning-on-implicit-conversion are
different games. Not checking for overflow is a good of C/C++.
Allowing unspecified behavior is good? How can that be?
If we need it, we can just write our own Int and overload the
operator+() to do the checking.
At a very, very high runtime cost; the checking is expensive.
If the compiler did it, all it needs to do is check the overflow
status flag after the addition. Very, very cheap.
To be really useful, of course, you'd want some sort of global
optimization. If I'm doing something like:
int d1 = rand() % 6 + 1 ;
int d2 = rand() % 6 + 1 ;
int throw = d1 + d2 ;
overflow checking on that final addition really isn't necessary.
A good compiler should be able to recognize this, and suppress
it. And of course, you'd also want to suppress it if you had
something like:
int d1 = throwDice() ; // post-condition: return value in
int d2 = throwDice() ; // range [1..6].
int throw = d1 + d2 ;
Which means the compiler must do inter-module analysis.
Alternatively, a pragma could be used to turn it off locally, if
the profiler showed it necessary.
And also it would be good if the compiler supports warnings on
porting specific errors.
You mean, for example, any time you suppose an int is more than
16 bits? Or your code depends on it being 2's complement?
Sun CC supports warnings for porting from 32 bit to 64 bit,
because the compiler was 32 bit (and only 32 bit) for the
longest time. Their warnings are only relevant to users of the
older compilers, when porting their code to the newer one. They
concern customers of a specific compiler; they are not designed
to be general portability warnings. I'm not sure what should be
included in general portability warnings; most programs really
don't have to be 100% portable (e.g. to a 1's complement 36 bit
machine).