<div class="gmail_quote">On Tue, May 1, 2012 at 10:39 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This patch allows reference types to be passed to llvm::dyn_cast -<br>
while always returning a pointer (since dyn_cast needs a way to<br>
communicate failure to the caller - unlike the standard dynamic_cast<br>
on references, which throws). A documentation update is included as<br>
well.<br>
<br>
This provides some flexibility to callers and actually models the<br>
contract more appropriately anyway - passing null to dyn_cast results<br>
in an assertion, so why not take something that describes that<br>
contract syntactically (a reference).</blockquote><div><br></div><div>I really don't like this:</div><div><br></div><div>1) it makes the behavior non-obvious from inspection: pointer-in, pointer-out is a useful invariant.</div>
<div>2) it breaks symmetry with cast: cast already handles references, but it returns a reference</div><div>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</div>
<div><br></div><div>Also, it seems to be solving a non-problem:</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> For context, this was motivated<br>
by some changes to iterators I've been making in clang - rather than<br>
having to dyn_cast(&*i) or make the iterator convertible to T* and<br>
provide simplify_type traits (to enable dyn_cast(i)),</blockquote><div><br></div><div>What's wrong with this? It seems to make everything behave more idiomatically...</div></div>