[PATCH] D42027: [Support][NFC] Improve isa implementation

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 24 11:27:34 PST 2018


In retrospect is it useful for Optional to be supported in isa? Since its
dynamic type is the same as its static type?

On Tue, Jan 23, 2018 at 10:50 PM Dmitry Borisenkov via Phabricator <
reviews at reviews.llvm.org> wrote:

> dmitry added inline comments.
>
>
> ================
> Comment at: unittests/Support/Casting.cpp:288-289
> +  EXPECT_TRUE(isa<Base>(DShared));
> +  llvm::Optional<Derived> DOpt;
> +  EXPECT_TRUE(isa<Base>(DOpt));
> +}
> ----------------
> dblaikie wrote:
> > Does this change then mean that one could cast<T> from Optional<Derived>
> to Optional<Base>? Because that'd be problematic, owing to Optional being a
> value-type. (it'd slice the object)
> This change doesn't modify casts behavior - just isa.
> As for the plan, cast should return T*, so
> ```
> Optional<Derived> DOpt;
> Base *b = cast<Base>(DOpt); //Just cast pointer to underlying data to
> Base*, does not handle potential ownership issues.
> ```
> should work, but it's ok.
> Move cast would be indeed problematic for value-types. So I would probably
> restrict it.
>
>
> https://reviews.llvm.org/D42027
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180124/d73718b1/attachment.html>


More information about the llvm-commits mailing list