Skip to content

Commit

Permalink
Bug#33559796: Single-argument constructors should be explicit (patch #1)
Browse files Browse the repository at this point in the history
This reduces the number of issues of type "Single - argument constructor
may inadvertently be used as a type conversion constructor"
as reported by Flint++ tool.
Some of the reported issues were not addressed:
 - lines explicitly marked with NOLINT (like plugin/x/src/prepare_param_handler.h)
 - false positives (tool reports alignas() calls as constructors)
 - issues where objects were intended to be used with type conversion
 - constructors with "const std::string &" param, to accept literal strings as well

Change-Id: I7eb6fabea7137fc7e81143f06ec7636b22f6ea97
  • Loading branch information
Miroslav Rajcic committed Nov 19, 2021
1 parent 2a272bc commit 0d745f4
Show file tree
Hide file tree
Showing 34 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion client/base/debug_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Debug_options : public Abstract_options_provider {
Constructs new debug options provider.
@param program Pointer to main program class.
*/
Debug_options(Abstract_program *program);
explicit Debug_options(Abstract_program *program);
/**
Creates all options that will be provided.
Implementation of Abstract_options_provider virtual method.
Expand Down
2 changes: 1 addition & 1 deletion client/base/help_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Help_options : public Abstract_options_provider {
@param program Pointer to main program class, used to collect list of all
options available in program.
*/
Help_options(Base::Abstract_program *program);
explicit Help_options(Base::Abstract_program *program);
/**
Creates all options that will be provided.
Implementation of Abstract_options_provider virtual method.
Expand Down
2 changes: 1 addition & 1 deletion client/base/mysql_connection_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Mysql_connection_options : public Composite_options_provider,
function from multiple threads simultaneously is not thread safe.
@param program Pointer to main program class.
*/
Mysql_connection_options(Abstract_program *program);
explicit Mysql_connection_options(Abstract_program *program);

/**
Creates all options that will be provided.
Expand Down
4 changes: 2 additions & 2 deletions client/base/mysql_query_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Mysql_query_runner {
/**
Standard constructor based on MySQL connection.
*/
Mysql_query_runner(MYSQL *connection);
explicit Mysql_query_runner(MYSQL *connection);
/**
Copy constructor.
*/
Expand Down Expand Up @@ -200,7 +200,7 @@ class Mysql_query_runner {

class Store_result_helper {
public:
Store_result_helper(std::vector<const Row *> *result);
explicit Store_result_helper(std::vector<const Row *> *result);
std::function<int64(const Row &)> *get_result_callback();

private:
Expand Down
4 changes: 2 additions & 2 deletions client/dump/abstract_connection_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Dump {

class Abstract_connection_provider : public I_connection_provider {
protected:
Abstract_connection_provider(
explicit Abstract_connection_provider(
Mysql::Tools::Base::I_connection_factory *connection_factory);

virtual Mysql::Tools::Base::Mysql_query_runner *create_new_runner(
Expand All @@ -49,7 +49,7 @@ class Abstract_connection_provider : public I_connection_provider {

class Message_handler_wrapper {
public:
Message_handler_wrapper(
explicit Message_handler_wrapper(
std::function<bool(const Mysql::Tools::Base::Message_data &)>
*message_handler);

Expand Down
2 changes: 1 addition & 1 deletion client/dump/abstract_database_dump_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Dump {
*/
class Abstract_database_dump_task : public Abstract_dump_task {
public:
Abstract_database_dump_task(Database *related_database);
explicit Abstract_database_dump_task(Database *related_database);

/**
Returns database the current task is created for.
Expand Down
2 changes: 1 addition & 1 deletion client/dump/abstract_dump_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Dump {
*/
class Abstract_dump_task : public Abstract_simple_dump_task {
public:
Abstract_dump_task(Abstract_data_object *related_object);
explicit Abstract_dump_task(Abstract_data_object *related_object);

~Abstract_dump_task() override;

Expand Down
2 changes: 1 addition & 1 deletion client/dump/abstract_table_dump_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Dump {
*/
class Abstract_table_dump_task : public Abstract_dump_task {
public:
Abstract_table_dump_task(Table *related_table);
explicit Abstract_table_dump_task(Table *related_table);

/**
Returns table the current task is created for.
Expand Down
2 changes: 1 addition & 1 deletion client/dump/chain_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Dump {

class Chain_data {
public:
Chain_data(uint64 chain_id);
explicit Chain_data(uint64 chain_id);

void abort();

Expand Down
2 changes: 1 addition & 1 deletion client/dump/composite_message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Composite_message_handler {
&message_handlers);

private:
Composite_message_handler(
explicit Composite_message_handler(
const std::vector<
std::function<bool(const Mysql::Tools::Base::Message_data &)> *>
&message_handlers);
Expand Down
2 changes: 1 addition & 1 deletion client/dump/database_end_dump_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Dump {

class Database_end_dump_task : public Abstract_database_dump_task {
public:
Database_end_dump_task(Database *related_database);
explicit Database_end_dump_task(Database *related_database);

~Database_end_dump_task() override;
};
Expand Down
2 changes: 1 addition & 1 deletion client/dump/database_start_dump_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Dump {

class Database_start_dump_task : public Abstract_database_dump_task {
public:
Database_start_dump_task(Database *related_database);
explicit Database_start_dump_task(Database *related_database);
};

} // namespace Dump
Expand Down
2 changes: 1 addition & 1 deletion client/dump/mysql_chain_element_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Dump {
class Mysql_chain_element_options
: public Mysql::Tools::Base::Options::Abstract_options_provider {
public:
Mysql_chain_element_options(
explicit Mysql_chain_element_options(
Mysql::Tools::Base::Abstract_connection_program *program);

void create_options() override;
Expand Down
2 changes: 1 addition & 1 deletion client/dump/mysql_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Dump {

class Mysql_field {
public:
Mysql_field(MYSQL_FIELD *field);
explicit Mysql_field(MYSQL_FIELD *field);

std::string get_name() const;

Expand Down
2 changes: 1 addition & 1 deletion client/dump/mysql_object_reader_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Dump {
class Mysql_object_reader_options
: public Mysql::Tools::Base::Options::Abstract_options_provider {
public:
Mysql_object_reader_options(
explicit Mysql_object_reader_options(
const Mysql_chain_element_options *mysql_chain_element_options);

void create_options() override;
Expand Down
2 changes: 1 addition & 1 deletion client/dump/mysqldump_tool_chain_maker_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern bool use_show_create_user;
class Mysqldump_tool_chain_maker_options
: public Mysql::Tools::Base::Options::Composite_options_provider {
public:
Mysqldump_tool_chain_maker_options(
explicit Mysqldump_tool_chain_maker_options(
const Mysql_chain_element_options *mysql_chain_element_options);

~Mysqldump_tool_chain_maker_options() override;
Expand Down
2 changes: 1 addition & 1 deletion client/dump/object_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Dump {
class Object_filter
: public Mysql::Tools::Base::Options::Composite_options_provider {
public:
Object_filter(Mysql::Tools::Base::Abstract_program *program);
explicit Object_filter(Mysql::Tools::Base::Abstract_program *program);

void create_options() override;

Expand Down
2 changes: 1 addition & 1 deletion client/dump/row.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Dump {
*/
class Row : public I_data_object {
public:
Row(const Mysql::Tools::Base::Mysql_query_runner::Row &row_data);
explicit Row(const Mysql::Tools::Base::Mysql_query_runner::Row &row_data);

~Row() override;

Expand Down
2 changes: 1 addition & 1 deletion client/dump/sql_formatter_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum class enum_gtid_purged_mode : unsigned long {
class Sql_formatter_options
: public Mysql::Tools::Base::Options::Abstract_options_provider {
public:
Sql_formatter_options(
explicit Sql_formatter_options(
const Mysql_chain_element_options *mysql_chain_element_options);

void create_options() override;
Expand Down
2 changes: 1 addition & 1 deletion client/dump/table_deferred_indexes_dump_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Dump {
*/
class Table_deferred_indexes_dump_task : public Abstract_table_dump_task {
public:
Table_deferred_indexes_dump_task(Table *related_table);
explicit Table_deferred_indexes_dump_task(Table *related_table);
};

} // namespace Dump
Expand Down
2 changes: 1 addition & 1 deletion client/dump/table_definition_dump_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Dump {
*/
class Table_definition_dump_task : public Abstract_table_dump_task {
public:
Table_definition_dump_task(Table *related_table);
explicit Table_definition_dump_task(Table *related_table);

~Table_definition_dump_task() override;
};
Expand Down
2 changes: 1 addition & 1 deletion client/dump/table_rows_dump_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Dump {
*/
class Table_rows_dump_task : public Abstract_table_dump_task {
public:
Table_rows_dump_task(Table *related_table);
explicit Table_rows_dump_task(Table *related_table);
};

} // namespace Dump
Expand Down
2 changes: 1 addition & 1 deletion client/dump/thread_specific_connection_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Dump {
class Thread_specific_connection_provider
: public Abstract_connection_provider {
public:
Thread_specific_connection_provider(
explicit Thread_specific_connection_provider(
Mysql::Tools::Base::I_connection_factory *connection_factory);
~Thread_specific_connection_provider() override;

Expand Down
2 changes: 1 addition & 1 deletion client/infix_ostream_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template <class T>
class infix_ostream_iterator
: public std::iterator<std::output_iterator_tag, T> {
public:
infix_ostream_iterator(std::ostream &s) : m_os(&s) {}
explicit infix_ostream_iterator(std::ostream &s) : m_os(&s) {}

infix_ostream_iterator(std::ostream &s, const char *d)
: m_os(&s), m_delimiter(d) {}
Expand Down
2 changes: 1 addition & 1 deletion client/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::ostream &operator<<(std::ostream &os, const Datetime &dt);

class Gen_spaces {
public:
Gen_spaces(int s) { m_spaces.assign(s, ' '); }
explicit Gen_spaces(int s) { m_spaces.assign(s, ' '); }
std::ostream &operator<<(std::ostream &os) { return os; }
friend std::ostream &operator<<(std::ostream &os, const Gen_spaces &gen);

Expand Down
2 changes: 1 addition & 1 deletion client/migrate_keyring/migrate_keyring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Log log_error(std::cerr, "ERROR");

class Migration_setup {
public:
Migration_setup(char *progname) {
explicit Migration_setup(char *progname) {
MY_INIT(progname);
init_components_subsystem();
init_connection_basic();
Expand Down
2 changes: 1 addition & 1 deletion client/migrate_keyring/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void deinit_connection_basic();

class Mysql_connection {
public:
Mysql_connection(bool connect);
explicit Mysql_connection(bool connect);
~Mysql_connection();
bool execute(std::string command);
bool ok() { return ok_; }
Expand Down
6 changes: 3 additions & 3 deletions client/mysql_ssl_rsa_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static void free_resources() {

class RSA_priv {
public:
RSA_priv(uint32_t key_size = 2048) : m_key_size(key_size) {}
explicit RSA_priv(uint32_t key_size = 2048) : m_key_size(key_size) {}

~RSA_priv() = default;

Expand Down Expand Up @@ -253,7 +253,7 @@ class RSA_pub {

class X509_key {
public:
X509_key(const Sql_string_t &version, uint32_t validity = 10 * 365L)
explicit X509_key(const Sql_string_t &version, uint32_t validity = 10 * 365L)
: m_validity(validity) {
m_subj_prefix << "-subj /CN=MySQL_Server_" << version;
}
Expand Down Expand Up @@ -312,7 +312,7 @@ class X509v3_ext_writer {

class X509_cert {
public:
X509_cert(uint32_t validity = 10 * 365L) : m_validity(validity) {}
explicit X509_cert(uint32_t validity = 10 * 365L) : m_validity(validity) {}

~X509_cert() = default;

Expand Down
7 changes: 4 additions & 3 deletions client/mysqlbinlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class Database_rewrite {
unsigned char **m_buffer{nullptr};

public:
Buffer_realloc_manager(unsigned char **buffer) : m_buffer{buffer} {}
explicit Buffer_realloc_manager(unsigned char **buffer)
: m_buffer{buffer} {}
~Buffer_realloc_manager() {
if (m_buffer != nullptr) free(*m_buffer);
}
Expand Down Expand Up @@ -209,7 +210,7 @@ class Database_rewrite {
}

public:
Transaction_payload_content_rewriter(Database_rewrite &rewriter)
explicit Transaction_payload_content_rewriter(Database_rewrite &rewriter)
: m_event_rewriter(rewriter) {}

/**
Expand Down Expand Up @@ -2575,7 +2576,7 @@ static void fix_gtid_set(MYSQL_RPL *rpl, uchar *packet_gtid_set) {
class Destroy_log_event_guard {
public:
Log_event **ev_del;
Destroy_log_event_guard(Log_event **ev_arg) { ev_del = ev_arg; }
explicit Destroy_log_event_guard(Log_event **ev_arg) { ev_del = ev_arg; }
~Destroy_log_event_guard() {
if (*ev_del != nullptr) delete *ev_del;
}
Expand Down
2 changes: 1 addition & 1 deletion libmysql/authentication_kerberos/auth_kerberos_client_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class Kerberos_client_io {
public:
Kerberos_client_io(MYSQL_PLUGIN_VIO *vio);
explicit Kerberos_client_io(MYSQL_PLUGIN_VIO *vio);
~Kerberos_client_io();
bool write_gssapi_buffer(const unsigned char *buffer, int buffer_len);
bool read_gssapi_buffer(unsigned char **gssapi_buffer, size_t *buffer_len);
Expand Down
8 changes: 4 additions & 4 deletions libmysql/authentication_win/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Blob {
Blob(const byte *ptr, const size_t len)
: m_ptr(const_cast<byte *>(ptr)), m_len(len) {}

Blob(const char *str)
explicit Blob(const char *str)
: m_ptr(const_cast<byte *>(reinterpret_cast<const byte *>(str))) {
m_len = strlen(str);
}
Expand Down Expand Up @@ -202,7 +202,7 @@ class Connection {
int m_error;

public:
Connection(MYSQL_PLUGIN_VIO *vio);
explicit Connection(MYSQL_PLUGIN_VIO *vio);
int write(const Blob &);
Blob read();

Expand All @@ -220,8 +220,8 @@ class Sid {
SID_NAME_USE m_type; ///< Type of identified entity.

public:
Sid(const wchar_t *);
Sid(HANDLE sec_token);
explicit Sid(const wchar_t *);
explicit Sid(HANDLE sec_token);
~Sid();

bool is_valid(void) const;
Expand Down
2 changes: 1 addition & 1 deletion libmysql/authentication_win/handshake.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Security_buffer : public SecBufferDesc {
const Security_buffer &operator=(const Security_buffer &);

public:
Security_buffer(const Blob &);
explicit Security_buffer(const Blob &);
Security_buffer();

~Security_buffer() { mem_free(); }
Expand Down
2 changes: 1 addition & 1 deletion libmysql/test_trace_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Logger {

public:
Logger() : connection_id(0), end(buffer) {}
Logger(MYSQL *conn);
explicit Logger(MYSQL *conn);
void log(const char *format, ...) MY_ATTRIBUTE((format(printf, 2, 3)));
void dump(const char *key, const void *data, size_t len);
};
Expand Down
2 changes: 1 addition & 1 deletion sql-common/oci/signing_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Signing_Key {

public:
Signing_Key(const std::string &file_name);
Signing_Key(ssl::Key_Content);
explicit Signing_Key(ssl::Key_Content);
Signing_Key();
Signing_Key(const Signing_Key &) = delete;
Signing_Key &operator=(const Signing_Key &) = delete;
Expand Down

0 comments on commit 0d745f4

Please sign in to comment.