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)
commit403011848502577344a222633918496fa03f32d4
tree53da2c91c823c5aae270237cc1e35b1126b0e362
parentba6d83e64b1923ccf56c843fdbb0fee11c45c5aa
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`.

llvm-svn: 222644
llvm/include/llvm/Support/Casting.h
llvm/unittests/Support/Casting.cpp