Skip to content

Commit

Permalink
Remove extraneous casts to void.
Browse files Browse the repository at this point in the history
This PR removes a number of extraneous casts to void, though not all in the same way. It does not have a goal of removing all of extraneous casts.

The most frequent by far is to prevent unused variable warnings for function arguments that are not actually used. In this case changing to an anonymous argument solves the problem. It also indicates quite clearly that an argument isn't used. In some cases checks for the validity of unused arguments were also removed.

In some cases a variable declaration (argument or otherwise) were annotated with `[[maybe_unused]]`. This was most often the case where the code varies with preprocessor definitions.

In a few cases some argument checks were promoted from `assert` to throwing exceptions when invalid. A handful of ignored return values were replaced with `std::ignore`.
  • Loading branch information
eric-hughes-tiledb committed Sep 20, 2023
1 parent fc72a4e commit 947b9bc
Show file tree
Hide file tree
Showing 34 changed files with 87 additions and 227 deletions.
24 changes: 9 additions & 15 deletions tiledb/sm/array_schema/dimension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1080,10 +1080,7 @@ void Dimension::splitting_value(
}

template <>
uint64_t Dimension::tile_num<char>(const Dimension* dim, const Range& range) {
(void)dim;
(void)range;

uint64_t Dimension::tile_num<char>(const Dimension*, const Range&) {
return 1;
}

Expand Down Expand Up @@ -1171,10 +1168,9 @@ ByteVecValue Dimension::map_from_uint64(

template <class T>
ByteVecValue Dimension::map_from_uint64(
const Dimension* dim, uint64_t value, int bits, uint64_t max_bucket_val) {
const Dimension* dim, uint64_t value, int, uint64_t max_bucket_val) {
assert(dim != nullptr);
assert(!dim->domain().empty());
(void)bits; // Not needed here

ByteVecValue ret(sizeof(T));

Expand Down Expand Up @@ -1205,11 +1201,7 @@ ByteVecValue Dimension::map_from_uint64(

template <>
ByteVecValue Dimension::map_from_uint64<char>(
const Dimension* dim, uint64_t value, int bits, uint64_t max_bucket_val) {
assert(dim != nullptr);
(void)dim;
(void)max_bucket_val; // Not needed here

const Dimension*, uint64_t value, int bits, uint64_t) {
std::vector<uint8_t> ret(sizeof(uint64_t)); // 8 bytes

uint64_t ret_uint64 = (value << (64 - bits));
Expand Down Expand Up @@ -1250,10 +1242,12 @@ bool Dimension::smaller_than(

template <>
bool Dimension::smaller_than<char>(
const Dimension* dim, const ByteVecValue& value, const Range& range) {
assert(dim != nullptr);
assert(value);
(void)dim;
const Dimension*, const ByteVecValue& value, const Range& range) {
// verify precondition for `rvalue_as`
if (!value) {
throw DimensionException(
"smaller_than<char>: operand `value` may not be empty");
}

auto value_str = value.rvalue_as<std::string>();
auto range_start_str = range.start_str();
Expand Down
12 changes: 2 additions & 10 deletions tiledb/sm/array_schema/domain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ uint64_t Domain::cell_num_per_tile() const {

template <>
int Domain::cell_order_cmp_impl<char>(
const Dimension* dim, const UntypedDatumView a, const UntypedDatumView b) {
// Must be var-sized
assert(dim->var_size());
(void)dim;

const Dimension*, const UntypedDatumView a, const UntypedDatumView b) {
auto var_a{a.value_as<const char[]>()};
auto var_b{b.value_as<const char[]>()};
auto size_a{a.size()};
Expand All @@ -230,10 +226,7 @@ int Domain::cell_order_cmp_impl<char>(

template <class T>
int Domain::cell_order_cmp_impl(
const Dimension* dim, const UntypedDatumView a, const UntypedDatumView b) {
assert(!dim->var_size());
(void)dim;

const Dimension*, const UntypedDatumView a, const UntypedDatumView b) {
auto ca = a.template value_as<T>();
auto cb = b.template value_as<T>();
if (ca < cb)
Expand Down Expand Up @@ -441,7 +434,6 @@ void Domain::get_end_of_cell_slab(
} else {
for (unsigned d = 0; d < dim_num_; ++d)
end[d] = start[d];
(void)subarray;
}
}

Expand Down
63 changes: 17 additions & 46 deletions tiledb/sm/c_api/tiledb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3416,11 +3416,8 @@ int32_t tiledb_deserialize_array(
tiledb_ctx_t* ctx,
const tiledb_buffer_t* buffer,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_array_t** array) {
// Currently unused:
(void)client_side;

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR)
return TILEDB_ERR;
Expand Down Expand Up @@ -3509,15 +3506,8 @@ int32_t tiledb_deserialize_array_schema(
tiledb_ctx_t* ctx,
const tiledb_buffer_t* buffer,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_array_schema_t** array_schema) {
// Currently unused:
(void)client_side;

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR)
return TILEDB_ERR;

api::ensure_buffer_is_valid(buffer);

// Create array schema struct
Expand Down Expand Up @@ -3547,11 +3537,10 @@ int32_t tiledb_serialize_array_open(
tiledb_ctx_t* ctx,
const tiledb_array_t* array,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_buffer_t** buffer) {
// Currently no different behaviour is required if array open is serialized by
// the client or the Cloud server, so the variable is unused
(void)client_side;
// Sanity check
if (sanity_check(ctx) == TILEDB_ERR ||
sanity_check(ctx, array) == TILEDB_ERR) {
Expand Down Expand Up @@ -3579,11 +3568,10 @@ int32_t tiledb_deserialize_array_open(
tiledb_ctx_t* ctx,
const tiledb_buffer_t* buffer,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_array_t** array) {
// Currently no different behaviour is required if array open is deserialized
// by the client or the Cloud server, so the variable is unused
(void)client_side;
// by the client or the Cloud server

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR) {
Expand Down Expand Up @@ -3674,11 +3662,8 @@ int32_t tiledb_deserialize_array_schema_evolution(
tiledb_ctx_t* ctx,
const tiledb_buffer_t* buffer,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_array_schema_evolution_t** array_schema_evolution) {
// Currently unused:
(void)client_side;

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR)
return TILEDB_ERR;
Expand Down Expand Up @@ -3857,11 +3842,8 @@ int32_t tiledb_serialize_array_nonempty_domain(
const void* nonempty_domain,
int32_t is_empty,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_buffer_t** buffer) {
// Currently unused:
(void)client_side;

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR || sanity_check(ctx, array) == TILEDB_ERR)
return TILEDB_ERR;
Expand Down Expand Up @@ -3890,12 +3872,9 @@ int32_t tiledb_deserialize_array_nonempty_domain(
const tiledb_array_t* array,
const tiledb_buffer_t* buffer,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
void* nonempty_domain,
int32_t* is_empty) {
// Currently unused:
(void)client_side;

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR || sanity_check(ctx, array) == TILEDB_ERR)
return TILEDB_ERR;
Expand All @@ -3919,11 +3898,8 @@ int32_t tiledb_serialize_array_non_empty_domain_all_dimensions(
tiledb_ctx_t* ctx,
const tiledb_array_t* array,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_buffer_t** buffer) {
// Currently unused:
(void)client_side;

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR || sanity_check(ctx, array) == TILEDB_ERR)
return TILEDB_ERR;
Expand All @@ -3950,10 +3926,7 @@ int32_t tiledb_deserialize_array_non_empty_domain_all_dimensions(
tiledb_array_t* array,
const tiledb_buffer_t* buffer,
tiledb_serialization_type_t serialize_type,
int32_t client_side) {
// Currently unused:
(void)client_side;

int32_t) {
// Sanity check
if (sanity_check(ctx) == TILEDB_ERR || sanity_check(ctx, array) == TILEDB_ERR)
return TILEDB_ERR;
Expand Down Expand Up @@ -4162,11 +4135,11 @@ int32_t tiledb_serialize_fragment_info_request(
tiledb_ctx_t* ctx,
const tiledb_fragment_info_t* fragment_info,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_buffer_t** buffer) {
// Currently no different behaviour is required if fragment info request is
// serialized by the client or the Cloud server, so the variable is unused
(void)client_side;
// serialized by the client or the Cloud server

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR ||
sanity_check(ctx, fragment_info) == TILEDB_ERR) {
Expand Down Expand Up @@ -4194,11 +4167,10 @@ int32_t tiledb_deserialize_fragment_info_request(
tiledb_ctx_t* ctx,
const tiledb_buffer_t* buffer,
tiledb_serialization_type_t serialize_type,
int32_t client_side,
int32_t,
tiledb_fragment_info_t* fragment_info) {
// Currently no different behaviour is required if fragment info request is
// serialized by the client or the Cloud server, so the variable is unused
(void)client_side;
// serialized by the client or the Cloud server

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR ||
Expand Down Expand Up @@ -4256,11 +4228,10 @@ int32_t tiledb_deserialize_fragment_info(
const tiledb_buffer_t* buffer,
tiledb_serialization_type_t serialize_type,
const char* array_uri,
int32_t client_side,
int32_t,
tiledb_fragment_info_t* fragment_info) {
// Currently no different behaviour is required if fragment info is
// deserialized by the client or the Cloud server, so the variable is unused
(void)client_side;
// deserialized by the client or the Cloud server

// Sanity check
if (sanity_check(ctx) == TILEDB_ERR ||
Expand Down
8 changes: 2 additions & 6 deletions tiledb/sm/c_api/tiledb_filestore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ int32_t tiledb_filestore_uri_import(
tiledb_ctx_t* ctx,
const char* filestore_array_uri,
const char* file_uri,
tiledb_mime_type_t mime_type) {
(void)mime_type; // Unused

tiledb_mime_type_t) {
if (sanity_check(ctx) == TILEDB_ERR || !filestore_array_uri || !file_uri) {
return TILEDB_ERR;
}
Expand Down Expand Up @@ -435,9 +433,7 @@ int32_t tiledb_filestore_buffer_import(
const char* filestore_array_uri,
void* buf,
size_t size,
tiledb_mime_type_t mime_type) {
(void)mime_type; // Unused

tiledb_mime_type_t) {
if (sanity_check(ctx) == TILEDB_ERR || !filestore_array_uri || !buf) {
return TILEDB_ERR;
}
Expand Down
3 changes: 1 addition & 2 deletions tiledb/sm/compressors/dd_compressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ Status DoubleDelta::decompress(
"Cannot decompress tile with DoubleDelta; Not supported datatype"));
}

uint64_t DoubleDelta::overhead(uint64_t nbytes) {
uint64_t DoubleDelta::overhead(uint64_t) {
// DoubleDelta has a fixed size overhead
(void)nbytes;
return DoubleDelta::OVERHEAD;
}

Expand Down
5 changes: 1 addition & 4 deletions tiledb/sm/compressors/lz4_compressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ using namespace tiledb::common;
namespace tiledb {
namespace sm {

Status LZ4::compress(
int level, ConstBuffer* input_buffer, Buffer* output_buffer) {
Status LZ4::compress(int, ConstBuffer* input_buffer, Buffer* output_buffer) {
// Sanity check
if (input_buffer->data() == nullptr || output_buffer->data() == nullptr)
return LOG_STATUS(Status_CompressionError(
"Failed compressing with LZ4; invalid buffer format"));

// TODO: level is ignored using the simple api interface
(void)level;
// Compress
#if LZ4_VERSION_NUMBER >= 10705
int ret = LZ4_compress_default(
Expand Down
4 changes: 1 addition & 3 deletions tiledb/sm/compressors/test/link_webp_test1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ typedef void VP8LDecoder;
extern "C" VP8LDecoder* VP8LNew(void);
extern "C" void VP8LClear(VP8LDecoder*);

int main(int argc, const char* argv[]) {
(void)argv;
(void)argc;
int main(int, const char*[]) {
int return_value = -1;
const char *in_file = NULL, *out_file = NULL;
FILE* out = NULL;
Expand Down
3 changes: 1 addition & 2 deletions tiledb/sm/consolidator/fragment_meta_consolidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ Status FragmentMetaConsolidator::consolidate(
RETURN_NOT_OK(enc_key.set_key(encryption_type, encryption_key, key_length));

GenericTileIO tile_io(storage_manager_->resources(), uri);
uint64_t nbytes = 0;
[[maybe_unused]] uint64_t nbytes = 0;
RETURN_NOT_OK(tile_io.write_generic(&tile, enc_key, &nbytes));
(void)nbytes;
RETURN_NOT_OK(storage_manager_->vfs()->close_file(uri));

return Status::Ok();
Expand Down
8 changes: 1 addition & 7 deletions tiledb/sm/consolidator/group_meta_consolidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,7 @@ GroupMetaConsolidator::GroupMetaConsolidator(
/* ****************************** */

Status GroupMetaConsolidator::consolidate(
const char* group_name,
EncryptionType encryption_type,
const void* encryption_key,
uint32_t key_length) {
(void)encryption_type;
(void)encryption_key;
(void)key_length;
const char* group_name, EncryptionType, const void*, uint32_t) {
auto timer_se = stats_->start_timer("consolidate_group_meta");

check_array_uri(group_name);
Expand Down
3 changes: 1 addition & 2 deletions tiledb/sm/cpp_api/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,7 @@ inline uint64_t VFSFilebuf::file_size() const {
return 0;
try {
return vfs_.get().file_size(uri_);
} catch (TileDBError& e) {
(void)e;
} catch (TileDBError&) {
return 0;
}
}
Expand Down
Loading

0 comments on commit 947b9bc

Please sign in to comment.