diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-07-07 15:05:44 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-07-08 12:39:26 +0100 |
commit | 31887c00fbdc7d607cf79b1042cb84d2c6db17e2 (patch) | |
tree | 7c8a8e057692377ea609f260bcb4f9516c63649d | |
parent | 2128789a386d098eb2068514baf3c85782c6a74e (diff) | |
download | gcc-31887c00fbdc7d607cf79b1042cb84d2c6db17e2.zip gcc-31887c00fbdc7d607cf79b1042cb84d2c6db17e2.tar.gz gcc-31887c00fbdc7d607cf79b1042cb84d2c6db17e2.tar.bz2 |
HIR::TypeParam needs to be permissive of nullptr Type
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-item.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 1d45186..1fcecb8 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -75,9 +75,12 @@ public: // Copy constructor uses clone TypeParam (TypeParam const &other) : GenericParam (other.mappings), outer_attr (other.outer_attr), - type_representation (other.type_representation), - type (other.type->clone_type ()), locus (other.locus) + type_representation (other.type_representation), locus (other.locus) { + // guard to prevent null pointer dereference + if (other.type != nullptr) + type = other.type->clone_type (); + type_param_bounds.reserve (other.type_param_bounds.size ()); for (const auto &e : other.type_param_bounds) type_param_bounds.push_back (e->clone_type_param_bound ()); @@ -87,19 +90,22 @@ public: TypeParam &operator= (TypeParam const &other) { type_representation = other.type_representation; - // type_param_bounds = other.type_param_bounds; - type = other.type->clone_type (); outer_attr = other.outer_attr; locus = other.locus; mappings = other.mappings; + // guard to prevent null pointer dereference + if (other.type != nullptr) + type = other.type->clone_type (); + else + type = nullptr; + type_param_bounds.reserve (other.type_param_bounds.size ()); for (const auto &e : other.type_param_bounds) type_param_bounds.push_back (e->clone_type_param_bound ()); return *this; } - // move constructors TypeParam (TypeParam &&other) = default; TypeParam &operator= (TypeParam &&other) = default; |