Attached is my long-awaited patch to implement checking of C++ casting operators. It's not 100% complete, but it's a start in the right direction. It checks that the reinterpret_cast, static_cast, and dynamic_cast operators don't "cast away const". The const_cast can, of course, do this, but only if the underlying base type is the same.

So a const_cast can cast from 'const double *' to 'double *', but not from 'const double *' to 'float *'. Whereas a reinterpret_cast can cast from 'const double *' to 'const float *', but not from 'const double *' to 'float *'. Etc.

Also, a reinterpret_cast cannot cast to a type that has smaller precision. So you can't cast from a 'void *' to 'char'.

Comments?
-bw

Attachment: casting.patch
Description: Binary data


_______________________________________________
cfe-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Reply via email to