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

Dmitry Borisenkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 22:50:48 PST 2018


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





More information about the llvm-commits mailing list