Warning on type conversion and type mismatch in device code.

How can one get warnings on type conversions or type mismatch in device code with cuda 5.0?

The ‘strongest’ warning I can artificially create is for the use of an initialized variable, but I can’t get the compiler to spit out a warning when adding a float to an int, or comparing a int to an unsigned int.


I am not aware of any compiler that emits a warning for adding a float and an int as there does not seem to be any particular risk in it. The comparison of signed and unsigned ints on the other hand can definitely lead to nasty bugs, as the int is converted to unsigned int prior to the comparison, with negative int operands turning into very large unsigned int operand.

I am not aware of any way of turning on a warning for signed / unsigned int comparisons with NVCC. I would suggest filing a feature request through the bug reporting form linked from the registered developer page. Please prefix the synopsis (subject line) with “RFE:” to mark it as a “request for enhancement”. Thanks!

If this hasn’t been RFE’d then it needs to be. I got burned by a signed / unsigned comparison for the last couple hours … much hilarity and hair-pulling ensued. Nsight helped me find it.

Lesson (re-re-re-)learned.