[llvm-commits] [patch] allow ref->pointer through dyn_cast

David Blaikie dblaikie at gmail.com
Tue May 1 10:39:10 PDT 2012


This patch allows reference types to be passed to llvm::dyn_cast -
while always returning a pointer (since dyn_cast needs a way to
communicate failure to the caller - unlike the standard dynamic_cast
on references, which throws). A documentation update is included as
well.

This provides some flexibility to callers and actually models the
contract more appropriately anyway - passing null to dyn_cast results
in an assertion, so why not take something that describes that
contract syntactically (a reference). For context, this was motivated
by some changes to iterators I've been making in clang - rather than
having to dyn_cast(&*i) or make the iterator convertible to T* and
provide simplify_type traits (to enable dyn_cast(i)), this seemed like
a nice utility/extensible solution to the main case.

There are various other ways this could've been implemented, other
than SFINAE, so I'm open to suggestions/preferences.

Thanks,
- David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dyn_cast_ref.diff
Type: application/octet-stream
Size: 3101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120501/d417cfa9/attachment.obj>


More information about the llvm-commits mailing list