Skip to content

Commit 0d745f4

Browse files
committed
Bug#33559796: Single-argument constructors should be explicit (patch #1)
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
1 parent 2a272bc commit 0d745f4

34 files changed

+44
-43
lines changed

client/base/debug_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Debug_options : public Abstract_options_provider {
4747
Constructs new debug options provider.
4848
@param program Pointer to main program class.
4949
*/
50-
Debug_options(Abstract_program *program);
50+
explicit Debug_options(Abstract_program *program);
5151
/**
5252
Creates all options that will be provided.
5353
Implementation of Abstract_options_provider virtual method.

client/base/help_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Help_options : public Abstract_options_provider {
4646
@param program Pointer to main program class, used to collect list of all
4747
options available in program.
4848
*/
49-
Help_options(Base::Abstract_program *program);
49+
explicit Help_options(Base::Abstract_program *program);
5050
/**
5151
Creates all options that will be provided.
5252
Implementation of Abstract_options_provider virtual method.

client/base/mysql_connection_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Mysql_connection_options : public Composite_options_provider,
7878
function from multiple threads simultaneously is not thread safe.
7979
@param program Pointer to main program class.
8080
*/
81-
Mysql_connection_options(Abstract_program *program);
81+
explicit Mysql_connection_options(Abstract_program *program);
8282

8383
/**
8484
Creates all options that will be provided.

client/base/mysql_query_runner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Mysql_query_runner {
5252
/**
5353
Standard constructor based on MySQL connection.
5454
*/
55-
Mysql_query_runner(MYSQL *connection);
55+
explicit Mysql_query_runner(MYSQL *connection);
5656
/**
5757
Copy constructor.
5858
*/
@@ -200,7 +200,7 @@ class Mysql_query_runner {
200200

201201
class Store_result_helper {
202202
public:
203-
Store_result_helper(std::vector<const Row *> *result);
203+
explicit Store_result_helper(std::vector<const Row *> *result);
204204
std::function<int64(const Row &)> *get_result_callback();
205205

206206
private:

client/dump/abstract_connection_provider.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Dump {
3737

3838
class Abstract_connection_provider : public I_connection_provider {
3939
protected:
40-
Abstract_connection_provider(
40+
explicit Abstract_connection_provider(
4141
Mysql::Tools::Base::I_connection_factory *connection_factory);
4242

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

5050
class Message_handler_wrapper {
5151
public:
52-
Message_handler_wrapper(
52+
explicit Message_handler_wrapper(
5353
std::function<bool(const Mysql::Tools::Base::Message_data &)>
5454
*message_handler);
5555

client/dump/abstract_database_dump_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Dump {
3737
*/
3838
class Abstract_database_dump_task : public Abstract_dump_task {
3939
public:
40-
Abstract_database_dump_task(Database *related_database);
40+
explicit Abstract_database_dump_task(Database *related_database);
4141

4242
/**
4343
Returns database the current task is created for.

client/dump/abstract_dump_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace Dump {
4242
*/
4343
class Abstract_dump_task : public Abstract_simple_dump_task {
4444
public:
45-
Abstract_dump_task(Abstract_data_object *related_object);
45+
explicit Abstract_dump_task(Abstract_data_object *related_object);
4646

4747
~Abstract_dump_task() override;
4848

client/dump/abstract_table_dump_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Dump {
3737
*/
3838
class Abstract_table_dump_task : public Abstract_dump_task {
3939
public:
40-
Abstract_table_dump_task(Table *related_table);
40+
explicit Abstract_table_dump_task(Table *related_table);
4141

4242
/**
4343
Returns table the current task is created for.

client/dump/chain_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Dump {
3333

3434
class Chain_data {
3535
public:
36-
Chain_data(uint64 chain_id);
36+
explicit Chain_data(uint64 chain_id);
3737

3838
void abort();
3939

client/dump/composite_message_handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Composite_message_handler {
4343
&message_handlers);
4444

4545
private:
46-
Composite_message_handler(
46+
explicit Composite_message_handler(
4747
const std::vector<
4848
std::function<bool(const Mysql::Tools::Base::Message_data &)> *>
4949
&message_handlers);

client/dump/database_end_dump_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Dump {
3434

3535
class Database_end_dump_task : public Abstract_database_dump_task {
3636
public:
37-
Database_end_dump_task(Database *related_database);
37+
explicit Database_end_dump_task(Database *related_database);
3838

3939
~Database_end_dump_task() override;
4040
};

client/dump/database_start_dump_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Dump {
3333

3434
class Database_start_dump_task : public Abstract_database_dump_task {
3535
public:
36-
Database_start_dump_task(Database *related_database);
36+
explicit Database_start_dump_task(Database *related_database);
3737
};
3838

3939
} // namespace Dump

client/dump/mysql_chain_element_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Dump {
3535
class Mysql_chain_element_options
3636
: public Mysql::Tools::Base::Options::Abstract_options_provider {
3737
public:
38-
Mysql_chain_element_options(
38+
explicit Mysql_chain_element_options(
3939
Mysql::Tools::Base::Abstract_connection_program *program);
4040

4141
void create_options() override;

client/dump/mysql_field.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Dump {
3737

3838
class Mysql_field {
3939
public:
40-
Mysql_field(MYSQL_FIELD *field);
40+
explicit Mysql_field(MYSQL_FIELD *field);
4141

4242
std::string get_name() const;
4343

client/dump/mysql_object_reader_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace Dump {
3838
class Mysql_object_reader_options
3939
: public Mysql::Tools::Base::Options::Abstract_options_provider {
4040
public:
41-
Mysql_object_reader_options(
41+
explicit Mysql_object_reader_options(
4242
const Mysql_chain_element_options *mysql_chain_element_options);
4343

4444
void create_options() override;

client/dump/mysqldump_tool_chain_maker_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern bool use_show_create_user;
4242
class Mysqldump_tool_chain_maker_options
4343
: public Mysql::Tools::Base::Options::Composite_options_provider {
4444
public:
45-
Mysqldump_tool_chain_maker_options(
45+
explicit Mysqldump_tool_chain_maker_options(
4646
const Mysql_chain_element_options *mysql_chain_element_options);
4747

4848
~Mysqldump_tool_chain_maker_options() override;

client/dump/object_filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Dump {
4040
class Object_filter
4141
: public Mysql::Tools::Base::Options::Composite_options_provider {
4242
public:
43-
Object_filter(Mysql::Tools::Base::Abstract_program *program);
43+
explicit Object_filter(Mysql::Tools::Base::Abstract_program *program);
4444

4545
void create_options() override;
4646

client/dump/row.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Dump {
3737
*/
3838
class Row : public I_data_object {
3939
public:
40-
Row(const Mysql::Tools::Base::Mysql_query_runner::Row &row_data);
40+
explicit Row(const Mysql::Tools::Base::Mysql_query_runner::Row &row_data);
4141

4242
~Row() override;
4343

client/dump/sql_formatter_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum class enum_gtid_purged_mode : unsigned long {
4545
class Sql_formatter_options
4646
: public Mysql::Tools::Base::Options::Abstract_options_provider {
4747
public:
48-
Sql_formatter_options(
48+
explicit Sql_formatter_options(
4949
const Mysql_chain_element_options *mysql_chain_element_options);
5050

5151
void create_options() override;

client/dump/table_deferred_indexes_dump_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Dump {
3636
*/
3737
class Table_deferred_indexes_dump_task : public Abstract_table_dump_task {
3838
public:
39-
Table_deferred_indexes_dump_task(Table *related_table);
39+
explicit Table_deferred_indexes_dump_task(Table *related_table);
4040
};
4141

4242
} // namespace Dump

client/dump/table_definition_dump_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Dump {
3636
*/
3737
class Table_definition_dump_task : public Abstract_table_dump_task {
3838
public:
39-
Table_definition_dump_task(Table *related_table);
39+
explicit Table_definition_dump_task(Table *related_table);
4040

4141
~Table_definition_dump_task() override;
4242
};

client/dump/table_rows_dump_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Dump {
3636
*/
3737
class Table_rows_dump_task : public Abstract_table_dump_task {
3838
public:
39-
Table_rows_dump_task(Table *related_table);
39+
explicit Table_rows_dump_task(Table *related_table);
4040
};
4141

4242
} // namespace Dump

client/dump/thread_specific_connection_provider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Dump {
4040
class Thread_specific_connection_provider
4141
: public Abstract_connection_provider {
4242
public:
43-
Thread_specific_connection_provider(
43+
explicit Thread_specific_connection_provider(
4444
Mysql::Tools::Base::I_connection_factory *connection_factory);
4545
~Thread_specific_connection_provider() override;
4646

client/infix_ostream_it.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ template <class T>
3131
class infix_ostream_iterator
3232
: public std::iterator<std::output_iterator_tag, T> {
3333
public:
34-
infix_ostream_iterator(std::ostream &s) : m_os(&s) {}
34+
explicit infix_ostream_iterator(std::ostream &s) : m_os(&s) {}
3535

3636
infix_ostream_iterator(std::ostream &s, const char *d)
3737
: m_os(&s), m_delimiter(d) {}

client/logger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ std::ostream &operator<<(std::ostream &os, const Datetime &dt);
3535

3636
class Gen_spaces {
3737
public:
38-
Gen_spaces(int s) { m_spaces.assign(s, ' '); }
38+
explicit Gen_spaces(int s) { m_spaces.assign(s, ' '); }
3939
std::ostream &operator<<(std::ostream &os) { return os; }
4040
friend std::ostream &operator<<(std::ostream &os, const Gen_spaces &gen);
4141

client/migrate_keyring/migrate_keyring.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Log log_error(std::cerr, "ERROR");
5656

5757
class Migration_setup {
5858
public:
59-
Migration_setup(char *progname) {
59+
explicit Migration_setup(char *progname) {
6060
MY_INIT(progname);
6161
init_components_subsystem();
6262
init_connection_basic();

client/migrate_keyring/options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void deinit_connection_basic();
9191

9292
class Mysql_connection {
9393
public:
94-
Mysql_connection(bool connect);
94+
explicit Mysql_connection(bool connect);
9595
~Mysql_connection();
9696
bool execute(std::string command);
9797
bool ok() { return ok_; }

client/mysql_ssl_rsa_setup.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static void free_resources() {
224224

225225
class RSA_priv {
226226
public:
227-
RSA_priv(uint32_t key_size = 2048) : m_key_size(key_size) {}
227+
explicit RSA_priv(uint32_t key_size = 2048) : m_key_size(key_size) {}
228228

229229
~RSA_priv() = default;
230230

@@ -253,7 +253,7 @@ class RSA_pub {
253253

254254
class X509_key {
255255
public:
256-
X509_key(const Sql_string_t &version, uint32_t validity = 10 * 365L)
256+
explicit X509_key(const Sql_string_t &version, uint32_t validity = 10 * 365L)
257257
: m_validity(validity) {
258258
m_subj_prefix << "-subj /CN=MySQL_Server_" << version;
259259
}
@@ -312,7 +312,7 @@ class X509v3_ext_writer {
312312

313313
class X509_cert {
314314
public:
315-
X509_cert(uint32_t validity = 10 * 365L) : m_validity(validity) {}
315+
explicit X509_cert(uint32_t validity = 10 * 365L) : m_validity(validity) {}
316316

317317
~X509_cert() = default;
318318

client/mysqlbinlog.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ class Database_rewrite {
125125
unsigned char **m_buffer{nullptr};
126126

127127
public:
128-
Buffer_realloc_manager(unsigned char **buffer) : m_buffer{buffer} {}
128+
explicit Buffer_realloc_manager(unsigned char **buffer)
129+
: m_buffer{buffer} {}
129130
~Buffer_realloc_manager() {
130131
if (m_buffer != nullptr) free(*m_buffer);
131132
}
@@ -209,7 +210,7 @@ class Database_rewrite {
209210
}
210211

211212
public:
212-
Transaction_payload_content_rewriter(Database_rewrite &rewriter)
213+
explicit Transaction_payload_content_rewriter(Database_rewrite &rewriter)
213214
: m_event_rewriter(rewriter) {}
214215

215216
/**
@@ -2575,7 +2576,7 @@ static void fix_gtid_set(MYSQL_RPL *rpl, uchar *packet_gtid_set) {
25752576
class Destroy_log_event_guard {
25762577
public:
25772578
Log_event **ev_del;
2578-
Destroy_log_event_guard(Log_event **ev_arg) { ev_del = ev_arg; }
2579+
explicit Destroy_log_event_guard(Log_event **ev_arg) { ev_del = ev_arg; }
25792580
~Destroy_log_event_guard() {
25802581
if (*ev_del != nullptr) delete *ev_del;
25812582
}

libmysql/authentication_kerberos/auth_kerberos_client_io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
class Kerberos_client_io {
2929
public:
30-
Kerberos_client_io(MYSQL_PLUGIN_VIO *vio);
30+
explicit Kerberos_client_io(MYSQL_PLUGIN_VIO *vio);
3131
~Kerberos_client_io();
3232
bool write_gssapi_buffer(const unsigned char *buffer, int buffer_len);
3333
bool read_gssapi_buffer(unsigned char **gssapi_buffer, size_t *buffer_len);

libmysql/authentication_win/common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Blob {
166166
Blob(const byte *ptr, const size_t len)
167167
: m_ptr(const_cast<byte *>(ptr)), m_len(len) {}
168168

169-
Blob(const char *str)
169+
explicit Blob(const char *str)
170170
: m_ptr(const_cast<byte *>(reinterpret_cast<const byte *>(str))) {
171171
m_len = strlen(str);
172172
}
@@ -202,7 +202,7 @@ class Connection {
202202
int m_error;
203203

204204
public:
205-
Connection(MYSQL_PLUGIN_VIO *vio);
205+
explicit Connection(MYSQL_PLUGIN_VIO *vio);
206206
int write(const Blob &);
207207
Blob read();
208208

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

222222
public:
223-
Sid(const wchar_t *);
224-
Sid(HANDLE sec_token);
223+
explicit Sid(const wchar_t *);
224+
explicit Sid(HANDLE sec_token);
225225
~Sid();
226226

227227
bool is_valid(void) const;

libmysql/authentication_win/handshake.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Security_buffer : public SecBufferDesc {
6666
const Security_buffer &operator=(const Security_buffer &);
6767

6868
public:
69-
Security_buffer(const Blob &);
69+
explicit Security_buffer(const Blob &);
7070
Security_buffer();
7171

7272
~Security_buffer() { mem_free(); }

libmysql/test_trace_plugin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class Logger {
182182

183183
public:
184184
Logger() : connection_id(0), end(buffer) {}
185-
Logger(MYSQL *conn);
185+
explicit Logger(MYSQL *conn);
186186
void log(const char *format, ...) MY_ATTRIBUTE((format(printf, 2, 3)));
187187
void dump(const char *key, const void *data, size_t len);
188188
};

sql-common/oci/signing_key.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Signing_Key {
4545

4646
public:
4747
Signing_Key(const std::string &file_name);
48-
Signing_Key(ssl::Key_Content);
48+
explicit Signing_Key(ssl::Key_Content);
4949
Signing_Key();
5050
Signing_Key(const Signing_Key &) = delete;
5151
Signing_Key &operator=(const Signing_Key &) = delete;

0 commit comments

Comments
 (0)