Support: Add *cast_or_null<> for pointer wrappers
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 24 Nov 2014 03:13:02 +0000 (03:13 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 24 Nov 2014 03:13:02 +0000 (03:13 +0000)
commit5deb1bf97fbe56de1c8c9aab32f11fdac4f2a5fb
tree21961a294db810d8b190977a9731e7c9813d53e5
parent84d3252d1bc44a4a9ba322a8f58ababfcfb29674
Support: Add *cast_or_null<> for pointer wrappers

Fill in omission of `cast_or_null<>` and `dyn_cast_or_null<>` for types
that wrap pointers (e.g., smart pointers).

Type traits need to be slightly stricter than for `cast<>` and
`dyn_cast<>` to resolve ambiguities with simple types.

There didn't seem to be any unit tests for pointer wrappers, so I tested
`isa<>`, `cast<>`, and `dyn_cast<>` while I was in there.

This only supports pointer wrappers with a conversion to `bool` to check
for null.  If in the future it's useful to support wrappers without such
a conversion, it should be a straightforward incremental step to use the
`simplify_type` machinery for the null check.  In that case, the unit
tests should be updated to remove the `operator bool()` from the
`pointer_wrappers::PTy`.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222644 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/Casting.h
unittests/Support/Casting.cpp