Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang Tidy, part 7 #9799

Merged
merged 14 commits into from
Mar 23, 2020
41 changes: 41 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Checks: '-*,
readability-simplify-subscript-expr,
readability-simplify-boolean-expr,
readability-inconsistent-declaration-parameter-name,
readability-identifier-naming,

bugprone-undelegated-constructor,
bugprone-argument-comment,
Expand Down Expand Up @@ -162,3 +163,43 @@ Checks: '-*,
boost-use-to-string,
'
WarningsAsErrors: '*'

CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.LocalVariableCase
value: lower_case
- key: readability-identifier-naming.StaticConstantCase
value: aNy_CasE
- key: readability-identifier-naming.MemberCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberPrefix
value: ''
- key: readability-identifier-naming.ProtectedMemberPrefix
value: ''
- key: readability-identifier-naming.PublicMemberCase
value: lower_case
- key: readability-identifier-naming.MethodCase
value: camelBack
- key: readability-identifier-naming.PrivateMethodPrefix
value: ''
- key: readability-identifier-naming.ProtectedMethodPrefix
value: ''
- key: readability-identifier-naming.ParameterPackCase
value: lower_case
- key: readability-identifier-naming.StructCase
value: CamelCase
- key: readability-identifier-naming.TemplateTemplateParameterCase
value: CamelCase
- key: readability-identifier-naming.TemplateUsingCase
value: lower_case
- key: readability-identifier-naming.TypeTemplateParameterCase
value: CamelCase
- key: readability-identifier-naming.TypedefCase
value: CamelCase
- key: readability-identifier-naming.UnionCase
value: CamelCase
- key: readability-identifier-naming.UsingCase
value: CamelCase
10 changes: 5 additions & 5 deletions base/common/shift10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
template <typename T>
static T shift10Impl(T x, int exponent)
{
static constexpr ssize_t MIN_EXPONENT = -323;
static constexpr ssize_t MAX_EXPONENT = 308;
static constexpr ssize_t min_exponent = -323;
static constexpr ssize_t max_exponent = 308;

static const long double powers10[] =
{
Expand Down Expand Up @@ -47,12 +47,12 @@ static T shift10Impl(T x, int exponent)
1e291L,1e292L,1e293L,1e294L,1e295L,1e296L,1e297L,1e298L,1e299L,1e300L,1e301L,1e302L,1e303L,1e304L,1e305L,1e306L,1e307L,1e308L
};

if (unlikely(exponent < MIN_EXPONENT)) /// Note: there are some values below MIN_EXPONENT that is greater than zero.
if (unlikely(exponent < min_exponent)) /// Note: there are some values below MIN_EXPONENT that is greater than zero.
x *= 0; /// Multiplying to keep the sign of zero.
else if (unlikely(exponent > MAX_EXPONENT))
else if (unlikely(exponent > max_exponent))
x *= std::numeric_limits<T>::infinity(); /// Multiplying to keep the sign of infinity.
else
x *= powers10[exponent - MIN_EXPONENT];
x *= powers10[exponent - min_exponent];

return x;
}
Expand Down
6 changes: 3 additions & 3 deletions base/common/tests/date_lut4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
int main(int, char **)
{
/** В DateLUT был глюк - для времён из дня 1970-01-01, возвращался номер часа больше 23. */
static const time_t TIME = 66130;
static const time_t time = 66130;

const auto & date_lut = DateLUT::instance();

std::cerr << date_lut.toHour(TIME) << std::endl;
std::cerr << date_lut.toDayNum(TIME) << std::endl;
std::cerr << date_lut.toHour(time) << std::endl;
std::cerr << date_lut.toDayNum(time) << std::endl;

const auto * values = reinterpret_cast<const DateLUTImpl::Values *>(&date_lut);

Expand Down
2 changes: 1 addition & 1 deletion base/mysqlxx/Pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Pool::~Pool()
}


Pool::Entry Pool::Get()
Pool::Entry Pool::get()
{
std::unique_lock<std::mutex> lock(mutex);

Expand Down
2 changes: 1 addition & 1 deletion base/mysqlxx/Pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class Pool final
~Pool();

/// Allocates connection.
Entry Get();
Entry get();

/// Allocates connection.
/// If database is not accessible, returns empty Entry object.
Expand Down
6 changes: 3 additions & 3 deletions base/mysqlxx/PoolFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ struct PoolFactory::Impl
std::mutex mutex;
};

PoolWithFailover PoolFactory::Get(const std::string & config_name, unsigned default_connections,
PoolWithFailover PoolFactory::get(const std::string & config_name, unsigned default_connections,
unsigned max_connections, size_t max_tries)
{
return Get(Poco::Util::Application::instance().config(), config_name, default_connections, max_connections, max_tries);
return get(Poco::Util::Application::instance().config(), config_name, default_connections, max_connections, max_tries);
}

/// Duplicate of code from StringUtils.h. Copied here for less dependencies.
Expand Down Expand Up @@ -72,7 +72,7 @@ static std::string getPoolEntryName(const Poco::Util::AbstractConfiguration & co
return entry_name;
}

PoolWithFailover PoolFactory::Get(const Poco::Util::AbstractConfiguration & config,
PoolWithFailover PoolFactory::get(const Poco::Util::AbstractConfiguration & config,
const std::string & config_name, unsigned default_connections, unsigned max_connections, size_t max_tries)
{

Expand Down
4 changes: 2 additions & 2 deletions base/mysqlxx/PoolFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class PoolFactory final : private boost::noncopyable
PoolFactory(const PoolFactory &) = delete;

/** Allocates a PoolWithFailover to connect to MySQL. */
PoolWithFailover Get(const std::string & config_name,
PoolWithFailover get(const std::string & config_name,
unsigned default_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
unsigned max_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_CONNECTIONS,
size_t max_tries = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_TRIES);

/** Allocates a PoolWithFailover to connect to MySQL. */
PoolWithFailover Get(const Poco::Util::AbstractConfiguration & config,
PoolWithFailover get(const Poco::Util::AbstractConfiguration & config,
const std::string & config_name,
unsigned default_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
unsigned max_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_CONNECTIONS,
Expand Down
6 changes: 3 additions & 3 deletions base/mysqlxx/PoolWithFailover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ PoolWithFailover::PoolWithFailover(const PoolWithFailover & other)
}
}

PoolWithFailover::Entry PoolWithFailover::Get()
PoolWithFailover::Entry PoolWithFailover::get()
{
Poco::Util::Application & app = Poco::Util::Application::instance();
std::lock_guard<std::mutex> locker(mutex);
Expand All @@ -89,7 +89,7 @@ PoolWithFailover::Entry PoolWithFailover::Get()

try
{
Entry entry = shareable ? pool->Get() : pool->tryGet();
Entry entry = shareable ? pool->get() : pool->tryGet();

if (!entry.isNull())
{
Expand Down Expand Up @@ -121,7 +121,7 @@ PoolWithFailover::Entry PoolWithFailover::Get()
if (full_pool)
{
app.logger().error("All connections failed, trying to wait on a full pool " + (*full_pool)->getDescription());
return (*full_pool)->Get();
return (*full_pool)->get();
}

std::stringstream message;
Expand Down
2 changes: 1 addition & 1 deletion base/mysqlxx/PoolWithFailover.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ namespace mysqlxx
PoolWithFailover(const PoolWithFailover & other);

/** Allocates a connection to use. */
Entry Get();
Entry get();
};
}
4 changes: 2 additions & 2 deletions base/mysqlxx/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ double Value::readFloatText(const char * buf, size_t length) const

void Value::throwException(const char * text) const
{
static constexpr size_t MYSQLXX_QUERY_PREVIEW_LENGTH = 1000;
static constexpr size_t preview_length = 1000;

std::stringstream info;
info << text;
Expand All @@ -166,7 +166,7 @@ void Value::throwException(const char * text) const
}

if (res && res->getQuery())
info << ", query: " << res->getQuery()->str().substr(0, MYSQLXX_QUERY_PREVIEW_LENGTH);
info << ", query: " << res->getQuery()->str().substr(0, preview_length);

throw CannotParseValue(info.str());
}
Expand Down
6 changes: 3 additions & 3 deletions dbms/programs/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ class Client : public Poco::Util::Application
/// to avoid losing sync.
if (!cancelled)
{
auto cancelQuery = [&] {
auto cancel_query = [&] {
connection->sendCancel();
cancelled = true;
if (is_interactive)
Expand All @@ -1134,7 +1134,7 @@ class Client : public Poco::Util::Application

if (interrupt_listener.check())
{
cancelQuery();
cancel_query();
}
else
{
Expand All @@ -1145,7 +1145,7 @@ class Client : public Poco::Util::Application
<< " Waited for " << static_cast<size_t>(elapsed) << " seconds,"
<< " timeout is " << receive_timeout.totalSeconds() << " seconds." << std::endl;

cancelQuery();
cancel_query();
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions dbms/programs/copier/ClusterCopierApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ void ClusterCopierApp::initialize(Poco::Util::Application & self)

void ClusterCopierApp::handleHelp(const std::string &, const std::string &)
{
Poco::Util::HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setHeader("Copies tables from one cluster to another");
helpFormatter.setUsage("--config-file <config-file> --task-path <task-path>");
helpFormatter.format(std::cerr);
Poco::Util::HelpFormatter help_formatter(options());
help_formatter.setCommand(commandName());
help_formatter.setHeader("Copies tables from one cluster to another");
help_formatter.setUsage("--config-file <config-file> --task-path <task-path>");
help_formatter.format(std::cerr);

stopOptionsProcessing();
}
Expand Down
10 changes: 5 additions & 5 deletions dbms/programs/odbc-bridge/ODBCBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ namespace

void ODBCBridge::handleHelp(const std::string &, const std::string &)
{
Poco::Util::HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setHeader("HTTP-proxy for odbc requests");
helpFormatter.setUsage("--http-port <port>");
helpFormatter.format(std::cerr);
Poco::Util::HelpFormatter help_formatter(options());
help_formatter.setCommand(commandName());
help_formatter.setHeader("HTTP-proxy for odbc requests");
help_formatter.setUsage("--http-port <port>");
help_formatter.format(std::cerr);

stopOptionsProcessing();
}
Expand Down
6 changes: 3 additions & 3 deletions dbms/programs/server/HTTPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void HTTPHandler::processQuery(
client_info.http_method = http_method;
client_info.http_user_agent = request.get("User-Agent", "");

auto appendCallback = [&context] (ProgressCallback callback)
auto append_callback = [&context] (ProgressCallback callback)
{
auto prev = context.getProgressCallback();

Expand All @@ -561,13 +561,13 @@ void HTTPHandler::processQuery(

/// While still no data has been sent, we will report about query execution progress by sending HTTP headers.
if (settings.send_progress_in_http_headers)
appendCallback([&used_output] (const Progress & progress) { used_output.out->onProgress(progress); });
append_callback([&used_output] (const Progress & progress) { used_output.out->onProgress(progress); });

if (settings.readonly > 0 && settings.cancel_http_readonly_queries_on_client_close)
{
Poco::Net::StreamSocket & socket = dynamic_cast<Poco::Net::HTTPServerRequestImpl &>(request).socket();

appendCallback([&context, &socket](const Progress &)
append_callback([&context, &socket](const Progress &)
{
/// Assume that at the point this method is called no one is reading data from the socket any more.
/// True for read-only queries.
Expand Down
4 changes: 2 additions & 2 deletions dbms/programs/server/HTTPHandlerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Poco::Net::HTTPRequestHandler * HTTPRequestHandlerFactoryMain::createRequestHand
<< ", Content Type: " << request.getContentType()
<< ", Transfer Encoding: " << request.getTransferEncoding());

for (auto & handlerFactory: child_handler_factories)
for (auto & handler_factory : child_handler_factories)
{
auto handler = handlerFactory->createRequestHandler(request);
auto handler = handler_factory->createRequestHandler(request);
if (handler != nullptr)
return handler;
}
Expand Down
4 changes: 2 additions & 2 deletions dbms/programs/server/MySQLHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ void MySQLHandler::comFieldList(ReadBuffer & payload)
ComFieldList packet;
packet.readPayload(payload);
String database = connection_context.getCurrentDatabase();
StoragePtr tablePtr = DatabaseCatalog::instance().getTable({database, packet.table});
for (const NameAndTypePair & column: tablePtr->getColumns().getAll())
StoragePtr table_ptr = DatabaseCatalog::instance().getTable({database, packet.table});
for (const NameAndTypePair & column: table_ptr->getColumns().getAll())
{
ColumnDefinition column_definition(
database, packet.table, packet.table, column.name, column.name, CharacterSet::binary, 100, ColumnType::MYSQL_TYPE_STRING, 0, 0
Expand Down
24 changes: 12 additions & 12 deletions dbms/programs/server/MySQLHandlerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ MySQLHandlerFactory::MySQLHandlerFactory(IServer & server_)
void MySQLHandlerFactory::readRSAKeys()
{
const Poco::Util::LayeredConfiguration & config = Poco::Util::Application::instance().config();
String certificateFileProperty = "openSSL.server.certificateFile";
String privateKeyFileProperty = "openSSL.server.privateKeyFile";
String certificate_file_property = "openSSL.server.certificateFile";
String private_key_file_property = "openSSL.server.privateKeyFile";

if (!config.has(certificateFileProperty))
if (!config.has(certificate_file_property))
throw Exception("Certificate file is not set.", ErrorCodes::NO_ELEMENTS_IN_CONFIG);

if (!config.has(privateKeyFileProperty))
if (!config.has(private_key_file_property))
throw Exception("Private key file is not set.", ErrorCodes::NO_ELEMENTS_IN_CONFIG);

{
String certificateFile = config.getString(certificateFileProperty);
FILE * fp = fopen(certificateFile.data(), "r");
String certificate_file = config.getString(certificate_file_property);
FILE * fp = fopen(certificate_file.data(), "r");
if (fp == nullptr)
throw Exception("Cannot open certificate file: " + certificateFile + ".", ErrorCodes::CANNOT_OPEN_FILE);
throw Exception("Cannot open certificate file: " + certificate_file + ".", ErrorCodes::CANNOT_OPEN_FILE);
SCOPE_EXIT(fclose(fp));

X509 * x509 = PEM_read_X509(fp, nullptr, nullptr, nullptr);
SCOPE_EXIT(X509_free(x509));
if (x509 == nullptr)
throw Exception("Failed to read PEM certificate from " + certificateFile + ". Error: " + getOpenSSLErrors(), ErrorCodes::OPENSSL_ERROR);
throw Exception("Failed to read PEM certificate from " + certificate_file + ". Error: " + getOpenSSLErrors(), ErrorCodes::OPENSSL_ERROR);

EVP_PKEY * p = X509_get_pubkey(x509);
if (p == nullptr)
Expand All @@ -88,16 +88,16 @@ void MySQLHandlerFactory::readRSAKeys()
}

{
String privateKeyFile = config.getString(privateKeyFileProperty);
String private_key_file = config.getString(private_key_file_property);

FILE * fp = fopen(privateKeyFile.data(), "r");
FILE * fp = fopen(private_key_file.data(), "r");
if (fp == nullptr)
throw Exception ("Cannot open private key file " + privateKeyFile + ".", ErrorCodes::CANNOT_OPEN_FILE);
throw Exception ("Cannot open private key file " + private_key_file + ".", ErrorCodes::CANNOT_OPEN_FILE);
SCOPE_EXIT(fclose(fp));

private_key.reset(PEM_read_RSAPrivateKey(fp, nullptr, nullptr, nullptr));
if (!private_key)
throw Exception("Failed to read RSA private key from " + privateKeyFile + ". Error: " + getOpenSSLErrors(), ErrorCodes::OPENSSL_ERROR);
throw Exception("Failed to read RSA private key from " + private_key_file + ". Error: " + getOpenSSLErrors(), ErrorCodes::OPENSSL_ERROR);
}
}

Expand Down
6 changes: 3 additions & 3 deletions dbms/programs/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ int Server::run()
{
if (config().hasOption("help"))
{
Poco::Util::HelpFormatter helpFormatter(Server::options());
Poco::Util::HelpFormatter help_formatter(Server::options());
std::stringstream header;
header << commandName() << " [OPTION] [-- [ARG]...]\n";
header << "positional arguments can be used to rewrite config.xml properties, for example, --http_port=8010";
helpFormatter.setHeader(header.str());
helpFormatter.format(std::cout);
help_formatter.setHeader(header.str());
help_formatter.format(std::cout);
return 0;
}
if (config().hasOption("version"))
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Access/QuotaCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ boost::shared_ptr<const EnabledQuota::Intervals> QuotaCache::QuotaInfo::rebuildI
new_intervals->quota_key = key;
auto & intervals = new_intervals->intervals;
intervals.reserve(quota->all_limits.size());
constexpr size_t MAX_RESOURCE_TYPE = Quota::MAX_RESOURCE_TYPE;
static constexpr size_t MAX_RESOURCE_TYPE = Quota::MAX_RESOURCE_TYPE;
for (const auto & limits : quota->all_limits)
{
intervals.emplace_back();
Expand Down