clang-tidy, part 4

This commit is contained in:
Alexey Milovidov 2020-03-09 00:40:00 +03:00
parent b53ec30978
commit 79c6bd5ae7
28 changed files with 50 additions and 52 deletions

View File

@ -1,2 +1,2 @@
Checks: '-*,google-readability-avoid-underscore-in-googletest-name,misc-throw-by-value-catch-by-reference,misc-misplaced-const,misc-unconventional-assign-operator,modernize-avoid-bind,modernize-loop-convert,modernize-make-shared,modernize-make-unique,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-random-shuffle,modernize-use-bool-literals,modernize-use-nullptr,modernize-use-using,performance-faster-string-find,performance-for-range-copy,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-qualified-auto,readability-redundant-access-specifiers,readability-redundant-control-flow,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,modernize-use-equals-default,modernize-use-equals-delete,bugprone-undelegated-constructor,readability-redundant-member-init,readability-simplify-subscript-expr,readability-simplify-boolean-expr,readability-inconsistent-declaration-parameter-name'
Checks: '-*,google-readability-avoid-underscore-in-googletest-name,misc-throw-by-value-catch-by-reference,misc-misplaced-const,misc-unconventional-assign-operator,modernize-avoid-bind,modernize-loop-convert,modernize-make-shared,modernize-make-unique,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-random-shuffle,modernize-use-bool-literals,modernize-use-nullptr,modernize-use-using,performance-faster-string-find,performance-for-range-copy,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-make-member-function-const,readability-misplaced-array-index,readability-non-const-parameter,readability-qualified-auto,readability-redundant-access-specifiers,readability-redundant-control-flow,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,modernize-use-equals-default,modernize-use-equals-delete,bugprone-undelegated-constructor,readability-redundant-member-init,readability-simplify-subscript-expr,readability-simplify-boolean-expr,readability-inconsistent-declaration-parameter-name'
WarningsAsErrors: '*'

View File

@ -45,7 +45,7 @@ void ConfigPreprocessor::removeConfigurationsIf(
{
auto checker = [&filter_type, &values, &leave] (XMLConfigurationPtr & config)
{
if (values.size() == 0)
if (values.empty())
return false;
bool remove_or_not = false;

View File

@ -148,7 +148,7 @@ private:
// The Algorithm complexity is O(n).
UInt8 getEventLevel(const Data & data) const
{
if (data.size() == 0)
if (data.empty())
return 0;
if (events_size == 1)
return 1;

View File

@ -424,7 +424,7 @@ ColumnPtr ColumnArray::filter(const Filter & filt, ssize_t result_size_hint) con
template <typename T>
ColumnPtr ColumnArray::filterNumber(const Filter & filt, ssize_t result_size_hint) const
{
if (getOffsets().size() == 0)
if (getOffsets().empty())
return ColumnArray::create(data);
auto res = ColumnArray::create(data->cloneEmpty());
@ -551,7 +551,7 @@ ColumnPtr ColumnArray::filterGeneric(const Filter & filt, ssize_t result_size_hi
ColumnPtr ColumnArray::filterNullable(const Filter & filt, ssize_t result_size_hint) const
{
if (getOffsets().size() == 0)
if (getOffsets().empty())
return ColumnArray::create(data);
const ColumnNullable & nullable_elems = assert_cast<const ColumnNullable &>(*data);
@ -574,7 +574,7 @@ ColumnPtr ColumnArray::filterNullable(const Filter & filt, ssize_t result_size_h
ColumnPtr ColumnArray::filterTuple(const Filter & filt, ssize_t result_size_hint) const
{
if (getOffsets().size() == 0)
if (getOffsets().empty())
return ColumnArray::create(data);
const ColumnTuple & tuple = assert_cast<const ColumnTuple &>(*data);

View File

@ -217,7 +217,7 @@ void ColumnDecimal<T>::gather(ColumnGathererStream & gatherer)
template <typename T>
void ColumnDecimal<T>::getExtremes(Field & min, Field & max) const
{
if (data.size() == 0)
if (data.empty())
{
min = NearestFieldType<T>(0, scale);
max = NearestFieldType<T>(0, scale);

View File

@ -100,7 +100,7 @@ void ColumnString::insertRangeFrom(const IColumn & src, size_t start, size_t len
ColumnPtr ColumnString::filter(const Filter & filt, ssize_t result_size_hint) const
{
if (offsets.size() == 0)
if (offsets.empty())
return ColumnString::create();
auto res = ColumnString::create();

View File

@ -156,7 +156,7 @@ protected:
template <typename ... TAllocatorParams>
void reserveForNextSize(TAllocatorParams &&... allocator_params)
{
if (size() == 0)
if (empty())
{
// The allocated memory should be multiplication of ELEMENT_SIZE to hold the element, otherwise,
// memory issue such as corruption could appear in edge case.

View File

@ -412,7 +412,7 @@ void ZooKeeperRequest::write(WriteBuffer & out) const
struct ZooKeeperResponse : virtual Response
{
virtual ~ZooKeeperResponse() {}
virtual ~ZooKeeperResponse() = default;
virtual void readImpl(ReadBuffer &) = 0;
};
@ -480,7 +480,7 @@ struct ZooKeeperCloseResponse final : ZooKeeperResponse
struct ZooKeeperCreateRequest final : CreateRequest, ZooKeeperRequest
{
ZooKeeperCreateRequest() {}
ZooKeeperCreateRequest() = default;
ZooKeeperCreateRequest(const CreateRequest & base) : CreateRequest(base) {}
ZooKeeper::OpNum getOpNum() const override { return 1; }
@ -512,7 +512,7 @@ struct ZooKeeperCreateResponse final : CreateResponse, ZooKeeperResponse
struct ZooKeeperRemoveRequest final : RemoveRequest, ZooKeeperRequest
{
ZooKeeperRemoveRequest() {}
ZooKeeperRemoveRequest() = default;
ZooKeeperRemoveRequest(const RemoveRequest & base) : RemoveRequest(base) {}
ZooKeeper::OpNum getOpNum() const override { return 2; }
@ -570,7 +570,7 @@ struct ZooKeeperGetResponse final : GetResponse, ZooKeeperResponse
struct ZooKeeperSetRequest final : SetRequest, ZooKeeperRequest
{
ZooKeeperSetRequest() {}
ZooKeeperSetRequest() = default;
ZooKeeperSetRequest(const SetRequest & base) : SetRequest(base) {}
ZooKeeper::OpNum getOpNum() const override { return 5; }
@ -613,7 +613,7 @@ struct ZooKeeperListResponse final : ListResponse, ZooKeeperResponse
struct ZooKeeperCheckRequest final : CheckRequest, ZooKeeperRequest
{
ZooKeeperCheckRequest() {}
ZooKeeperCheckRequest() = default;
ZooKeeperCheckRequest(const CheckRequest & base) : CheckRequest(base) {}
ZooKeeper::OpNum getOpNum() const override { return 13; }

View File

@ -196,7 +196,7 @@ private:
using RequestsQueue = ConcurrentBoundedQueue<RequestInfo>;
RequestsQueue requests_queue{1};
void pushRequest(RequestInfo && request);
void pushRequest(RequestInfo && info);
using Operations = std::map<XID, RequestInfo>;

View File

@ -168,11 +168,11 @@ static void test2()
ASSERT_CHECK((arr[1] == 2), res);
ASSERT_CHECK((arr[2] == 3), res);
ASSERT_CHECK((arr2.size() == 0), res);
ASSERT_CHECK((arr2.empty()), res);
arr.swap(arr2);
ASSERT_CHECK((arr.size() == 0), res);
ASSERT_CHECK((arr.empty()), res);
ASSERT_CHECK((arr2.size() == 3), res);
ASSERT_CHECK((arr2[0] == 1), res);
@ -200,11 +200,11 @@ static void test2()
ASSERT_CHECK((arr[3] == 4), res);
ASSERT_CHECK((arr[4] == 5), res);
ASSERT_CHECK((arr2.size() == 0), res);
ASSERT_CHECK((arr2.empty()), res);
arr.swap(arr2);
ASSERT_CHECK((arr.size() == 0), res);
ASSERT_CHECK((arr.empty()), res);
ASSERT_CHECK((arr2.size() == 5), res);
ASSERT_CHECK((arr2[0] == 1), res);
@ -409,7 +409,7 @@ static void test3()
Array arr2{std::move(arr)};
ASSERT_CHECK((arr.size() == 0), res);
ASSERT_CHECK((arr.empty()), res);
ASSERT_CHECK((arr2.size() == 3), res);
ASSERT_CHECK((arr2[0] == 1), res);
@ -428,7 +428,7 @@ static void test3()
Array arr2{std::move(arr)};
ASSERT_CHECK((arr.size() == 0), res);
ASSERT_CHECK((arr.empty()), res);
ASSERT_CHECK((arr2.size() == 5), res);
ASSERT_CHECK((arr2[0] == 1), res);

View File

@ -61,7 +61,7 @@ bool CachedCompressedReadBuffer::nextImpl()
cache->set(key, owned_cell);
}
if (owned_cell->data.size() == 0)
if (owned_cell->data.empty())
return false;
working_buffer = Buffer(owned_cell->data.data(), owned_cell->data.data() + owned_cell->data.size() - owned_cell->additional_bytes);

View File

@ -156,7 +156,7 @@ Block ParallelParsingBlockInputStream::readImpl()
next_block_in_current_unit = 0;
}
if (unit.block_ext.block.size() == 0)
if (unit.block_ext.block.empty())
{
/*
* Can we get zero blocks for an entire segment, when the format parser

View File

@ -235,7 +235,7 @@ getArgument(const ASTPtr & arguments, size_t argument_index, const char * argume
static DataTypePtr create64(const String & /*type_name*/, const ASTPtr & arguments)
{
if (!arguments || arguments->size() == 0)
if (!arguments || arguments->empty())
return std::make_shared<DataTypeDateTime64>(DataTypeDateTime64::default_scale);
const auto scale = getArgument<UInt64, ArgumentKind::Optional>(arguments, 0, "scale", "DateType64");

View File

@ -292,7 +292,7 @@ std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
for (const auto & config_elem : config_elems)
{
if (!startsWith(config_elem.data(), "attribute"))
if (!startsWith(config_elem, "attribute"))
continue;
const auto prefix = config_prefix + '.' + config_elem + '.';

View File

@ -112,7 +112,7 @@ void validateArgumentType(const IFunction & func, const DataTypes & arguments,
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
const auto & argument = arguments[argument_index];
if (validator_func(*argument) == false)
if (!validator_func(*argument))
throw Exception("Illegal type " + argument->getName() +
" of " + std::to_string(argument_index) +
" argument of function " + func.getName() +
@ -151,10 +151,10 @@ void validateArgumentsImpl(const IFunction & func,
int FunctionArgumentDescriptor::isValid(const DataTypePtr & data_type, const ColumnPtr & column) const
{
if (type_validator_func && (data_type == nullptr || type_validator_func(*data_type) == false))
if (type_validator_func && (data_type == nullptr || !type_validator_func(*data_type)))
return ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT;
if (column_validator_func && (column == nullptr || column_validator_func(*column) == false))
if (column_validator_func && (column == nullptr || !column_validator_func(*column)))
return ErrorCodes::ILLEGAL_COLUMN;
return 0;
@ -194,20 +194,18 @@ void validateFunctionArgumentTypes(const IFunction & func,
throw Exception("Incorrect number of arguments for function " + func.getName()
+ " provided " + std::to_string(arguments.size())
+ (arguments.size() ? " (" + joinArgumentTypes(arguments) + ")" : String{})
+ (!arguments.empty() ? " (" + joinArgumentTypes(arguments) + ")" : String{})
+ ", expected " + std::to_string(mandatory_args.size())
+ (optional_args.size() ? " to " + std::to_string(mandatory_args.size() + optional_args.size()) : "")
+ (!optional_args.empty() ? " to " + std::to_string(mandatory_args.size() + optional_args.size()) : "")
+ " (" + joinArgumentTypes(mandatory_args)
+ (optional_args.size() ? ", [" + joinArgumentTypes(optional_args) + "]" : "")
+ (!optional_args.empty() ? ", [" + joinArgumentTypes(optional_args) + "]" : "")
+ ")",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
}
validateArgumentsImpl(func, arguments, 0, mandatory_args);
if (optional_args.size())
{
if (!optional_args.empty())
validateArgumentsImpl(func, arguments, mandatory_args.size(), optional_args);
}
}
std::pair<std::vector<const IColumn *>, const ColumnArray::Offset *>

View File

@ -898,7 +898,7 @@ public:
String needle = c1_const->getValue<String>();
String replacement = c2_const->getValue<String>();
if (needle.size() == 0)
if (needle.empty())
throw Exception("Length of the second argument of function replace must be greater than 0.", ErrorCodes::ARGUMENT_OUT_OF_BOUND);
if (const ColumnString * col = checkAndGetColumn<ColumnString>(column_src.get()))

View File

@ -39,7 +39,7 @@ public:
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments.size() == 0)
if (arguments.empty())
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
+ toString(arguments.size()) + ", should be at least 1.",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

View File

@ -98,7 +98,7 @@ public:
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
{
if (arguments.size() == 0)
if (arguments.empty())
throw Exception(
"Number of arguments for function " + getName() + " doesn't match: passed " + std::to_string(arguments.size())
+ ", should be at least 1.",

View File

@ -41,7 +41,7 @@ public:
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments.size() == 0)
if (arguments.empty())
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
+ toString(arguments.size()) + ", should be at least 1.",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

View File

@ -38,7 +38,7 @@ std::string extractTimeZoneNameFromFunctionArguments(const ColumnsWithTypeAndNam
}
else
{
if (!arguments.size())
if (arguments.empty())
return {};
/// If time zone is attached to an argument of type DateTime.
@ -57,7 +57,7 @@ const DateLUTImpl & extractTimeZoneFromFunctionArguments(Block & block, const Co
return DateLUT::instance(extractTimeZoneNameFromColumn(*block.getByPosition(arguments[time_zone_arg_num]).column));
else
{
if (!arguments.size())
if (arguments.empty())
return DateLUT::instance();
/// If time zone is attached to an argument of type DateTime.

View File

@ -2324,7 +2324,7 @@ void Aggregator::destroyWithoutKey(AggregatedDataVariants & result) const
void Aggregator::destroyAllAggregateStates(AggregatedDataVariants & result)
{
if (result.size() == 0)
if (result.empty())
return;
LOG_TRACE(log, "Destroying aggregate states");

View File

@ -98,7 +98,7 @@ std::vector<ASTs> PredicateExpressionsOptimizer::extractTablesPredicates(const A
{
if (expression_info.unique_reference_tables_pos.size() == 1)
tables_predicates[*expression_info.unique_reference_tables_pos.begin()].emplace_back(predicate_expression);
else if (expression_info.unique_reference_tables_pos.size() == 0)
else if (expression_info.unique_reference_tables_pos.empty())
{
for (size_t index = 0; index < tables_predicates.size(); ++index)
tables_predicates[index].emplace_back(predicate_expression);

View File

@ -281,7 +281,7 @@ ProcessListEntry::~ProcessListEntry()
user_process_list.resetTrackers();
/// This removes memory_tracker for all requests. At this time, no other memory_trackers live.
if (parent.processes.size() == 0)
if (parent.processes.empty())
{
/// Reset MemoryTracker, similarly (see above).
parent.total_memory_tracker.logPeakMemoryUsage();

View File

@ -598,7 +598,7 @@ void executeQuery(
const char * end;
/// If 'istr' is empty now, fetch next data into buffer.
if (istr.buffer().size() == 0)
if (istr.buffer().empty())
istr.next();
size_t max_query_size = context.getSettingsRef().max_query_size;

View File

@ -11,7 +11,7 @@ Block LazyOutputFormat::getBlock(UInt64 milliseconds)
{
if (finished_processing)
{
if (queue.size() == 0)
if (queue.empty())
return {};
}

View File

@ -292,7 +292,7 @@ bool StorageKafka::checkDependencies(const StorageID & table_id)
{
// Check if all dependencies are attached
auto dependencies = global_context.getDependencies(table_id);
if (dependencies.size() == 0)
if (dependencies.empty())
return true;
// Check the dependencies are ready?
@ -324,7 +324,7 @@ void StorageKafka::threadFunc()
auto dependencies = global_context.getDependencies(table_id);
// Keep streaming as long as there are attached views and streaming is not cancelled
while (!stream_cancelled && num_created_consumers > 0 && dependencies.size() > 0)
while (!stream_cancelled && num_created_consumers > 0 && !dependencies.empty())
{
if (!checkDependencies(table_id))
break;
@ -543,7 +543,7 @@ void registerStorageKafka(StorageFactory & factory)
{
throw Exception("Row delimiter must be a char", ErrorCodes::BAD_ARGUMENTS);
}
else if (arg.size() == 0)
else if (arg.empty())
{
row_delimiter = '\0';
}

View File

@ -265,7 +265,7 @@ void ReplicatedMergeTreeQueue::removePartFromMutations(const String & part_name)
MutationStatus & status = *it->second;
status.parts_to_do.removePartAndCoveredParts(part_name);
if (status.parts_to_do.size() == 0)
if (status.parts_to_do.empty())
some_mutations_are_probably_done = true;
if (!status.latest_failed_part.empty() && part_info.contains(status.latest_failed_part_info))
@ -695,7 +695,7 @@ void ReplicatedMergeTreeQueue::updateMutations(zkutil::ZooKeeperPtr zookeeper, C
}
}
if (mutation.parts_to_do.size() == 0)
if (mutation.parts_to_do.empty())
{
some_mutations_are_probably_done = true;
}
@ -1377,7 +1377,7 @@ bool ReplicatedMergeTreeQueue::tryFinalizeMutations(zkutil::ZooKeeperPtr zookeep
mutation.parts_to_do.clear();
}
}
else if (mutation.parts_to_do.size() == 0)
else if (mutation.parts_to_do.empty())
{
LOG_TRACE(log, "Will check if mutation " << mutation.entry->znode_name << " is done");
candidates.push_back(mutation.entry);

View File

@ -57,7 +57,7 @@ void extractFunctions(const ASTPtr & expression, const NameSet & columns, std::v
/// Construct a conjunction from given functions
ASTPtr buildWhereExpression(const ASTs & functions)
{
if (functions.size() == 0)
if (functions.empty())
return nullptr;
if (functions.size() == 1)
return functions[0];