[cfe-dev] Smart pointers for canonical types
Douglas Gregor
dgregor at apple.com
Wed Jul 15 07:58:36 PDT 2009
Hello all,
Last week a few of us discussed potential improvements to Clang's use
of canonical types. At issue is our continuing concern that it is too
easy to accidentally compare non-canonical QualTypes, and each place
we've made this mistake will only be exposed when some poor user has a
typedef where we haven't yet seen one.
The attached patch introduces a new class template CanQual<T>, which
is a smart pointer that refers to a canonical type whose dynamic type
is T or some subclass thereof. T will often be Type, but we also
expect that, e.g., CanQual<PointerType> will be used rather than const
PointerType*.
ASTContext's getCanonicalType() now returns a CanQual<Type> (also
named CanQualType). CanQual<T> provides the appropriate conversions to
QualType and const T* so that existing code continues to work. We can
gradually move type-checking code over toward CanQual<T> to improve
safety. The design is such that, once complete, accessing members of
PointerType through CanQual<PointerType> will always return
*canonical* types (e.g., a CanQual<Type>) so that it's easy to stay
within the static canonical-types system.
Comments and questions greatly appreciated!
- Doug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: type-traits.patch
Type: application/octet-stream
Size: 1231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090715/70ad65e8/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: can-qual-ptr.patch
Type: application/octet-stream
Size: 19232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090715/70ad65e8/attachment-0001.obj>
More information about the cfe-dev
mailing list