[cfe-dev] For Review: C++ Casting Patch

Bill Wendling isanbard at gmail.com
Fri Mar 28 22:03:26 PDT 2008

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'.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: casting.patch
Type: application/octet-stream
Size: 22570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080328/7bbd7c51/attachment.obj>
-------------- next part --------------

More information about the cfe-dev mailing list