Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Warn on implicit conversion that may change sign of integer value

ZES
Beginner
759 Views

Hello,

when compiling the following code

unsigned int bad_sign_conv(int i)
{
   unsigned int u = i;
   return u;
}

with Intel(R) C++ Compiler XE for applications running on IA-32, Version 13.1.3.192 Build 20130607 like so

$ icpc -c -Wconversion -Wsign-conversion demo.cc

no diagnostics are emitted.

When compiling with e.g. g++ (Debian 4.4.5-8) 4.4.5 with the same switches, like so

$ g++ -c -Wconversion -Wsign-conversion demo.cc

demo.cc: In function ‘unsigned int bad_sign_conv(int)’:

demo.cc:3: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result

above warning is emitted as expected.  How do I get Intel C++ to warn me likewise?

PS There is also a "Diagnostic 68: integer conversion resulted in a change of sign", but that seems to trigger only when the sign is definitely changed?  (https://software.intel.com/en-us/articles/cdiag68)

0 Kudos
3 Replies
Shenghong_G_Intel
759 Views

Hello ZES,

Looks like ICC does not have any option to warn on this code. I will file a feature request to developer team, hope they will provide a fix, to be compatible with GCC.

Thanks,

Shenghong

0 Kudos
Shenghong_G_Intel
759 Views

Hello ZES,

Talked with developer, he said "Intel does not warn on potential sign conversions with -Wsign-conversion, only actual ones." (as you already mentioned). He think that this is preferable to GNU's more aggressive warning. So, we will not fix it.

Do you have a strong reason why you need such warning for potential sign conversions?

Thanks,

Shenghong

0 Kudos
ZES
Beginner
759 Views

Hello Shenghong,

thanks for your replies and efforts.  Apologies for the veeery long round-trip time, but somehow we were not notified about your second reply (e-mail problems most likely) and I just noticed it the other day.

Anyway, our strong reason and preference for GNU's more "aggressive" warning behaviour is already found in the code snippet provided in OP: We were dealing with a bug where such a (potential) change of sign actually occured every now and then and it took us quite some time to track down the assignment where it happened (as part of some elaborate computation).  A respective warning would have clearly helped us here, and requiring an explicit cast to silence it is IMHO not unreasonable (and clearly communicates the intent or calls attention to a mistake).

BTW Would it make a difference now if I'd submit the issue with Intel's Premier Support?

Thanks again
Oliver

0 Kudos
Reply