diff options
author | Richard Biener <rguenther@suse.de> | 2023-04-21 13:38:53 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-04-21 15:53:21 +0200 |
commit | 2e047c00e983b6d9037906feac3a215ef829c82f (patch) | |
tree | 379027430395b2c9f50a4921510a22283b1cc96a /gcc | |
parent | c39cdd9e654540f74cd2478019c40f1611554a44 (diff) | |
download | gcc-2e047c00e983b6d9037906feac3a215ef829c82f.zip gcc-2e047c00e983b6d9037906feac3a215ef829c82f.tar.gz gcc-2e047c00e983b6d9037906feac3a215ef829c82f.tar.bz2 |
Add safe_is_a
The following adds safe_is_a, an is_a check handling nullptr
gracefully.
* is-a.h (safe_is_a): New.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/is-a.h | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -232,6 +232,19 @@ is_a (U *p) return is_a_helper<T>::test (p); } +/* Similar to is_a<>, but where the pointer can be NULL, even if + is_a_helper<T> doesn't check for NULL. */ + +template <typename T, typename U> +inline bool +safe_is_a (U *p) +{ + if (p) + return is_a_helper <T>::test (p); + else + return false; +} + /* A generic conversion from a base type U to a derived type T. See the discussion above for when to use this function. */ |