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

Chandler Carruth chandlerc at google.com
Tue May 1 10:57:04 PDT 2012


On Tue, May 1, 2012 at 10:39 AM, David Blaikie <dblaikie at gmail.com> wrote:

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


I really don't like this:

1) it makes the behavior non-obvious from inspection: pointer-in,
pointer-out is a useful invariant.
2) it breaks symmetry with cast: cast already handles references, but it
returns a reference
3) it breaks symmetry with dyn_cast_or_null: either this function accepts a
reference, which makes no sense at all, or it accepts different types

Also, it seems to be solving a non-problem:


> 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)),


What's wrong with this? It seems to make everything behave more
idiomatically...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120501/426b8c24/attachment.html>


More information about the llvm-commits mailing list