aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h16
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;