Skip to content

Commit

Permalink
Prevent compiler warning about writing to an object with no trivial c…
Browse files Browse the repository at this point in the history
…opy-assignment
  • Loading branch information
How Si Wei committed Jun 27, 2019
1 parent 8b7d956 commit 95e5e93
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/sparsehash/sparsetable
Expand Up @@ -1088,7 +1088,9 @@ class sparsegroup {
// This is equivalent to memmove(), but faster on my Intel P4,
// at least with gcc4.1 -O2 / glibc 2.3.6.
for (size_type i = settings.num_buckets; i > offset; --i)
memcpy(group + i, group + i-1, sizeof(*group));
// cast to void* to prevent compiler warnings about writing to an object
// with no trivial copy-assignment
memcpy(static_cast<void*>(group + i), group + i-1, sizeof(*group));
}

// Create space at group[offset], without special assumptions about value_type
Expand Down Expand Up @@ -1154,7 +1156,10 @@ class sparsegroup {
// at lesat with gcc4.1 -O2 / glibc 2.3.6.
assert(settings.num_buckets > 0);
for (size_type i = offset; i < settings.num_buckets-1; ++i)
memcpy(group + i, group + i+1, sizeof(*group)); // hopefully inlined!
// cast to void* to prevent compiler warnings about writing to an object
// with no trivial copy-assignment
// hopefully inlined!
memcpy(static_cast<void*>(group + i), group + i+1, sizeof(*group));
group = settings.realloc_or_die(group, settings.num_buckets-1);
}

Expand Down

0 comments on commit 95e5e93

Please sign in to comment.