Skip to content

Commit

Permalink
Apply clang-tidy to remove empty constructors / destructors
Browse files Browse the repository at this point in the history
This patch is the result of running
run-clang-tidy -fix -header-filter=.* -checks='-*,modernize-use-equals-default' .

Code style changes have been done on top. The result of this change
leads to the following improvements:

1. Binary size reduction.
* For a -DBUILD_CONFIG=mysql_release build, the binary size is reduced by
  ~400kb.
* A raw -DCMAKE_BUILD_TYPE=Release reduces the binary size by ~1.4kb.

2. Compiler can better understand the intent of the code, thus it leads
   to more optimization possibilities. Additionally it enabled detecting
   unused variables that had an empty default constructor but not marked
   so explicitly.

   Particular change required following this patch in sql/opt_range.cc

   result_keys, an unused template class Bitmap now correctly issues
   unused variable warnings.

   Setting Bitmap template class constructor to default allows the compiler
   to identify that there are no side-effects when instantiating the class.
   Previously the compiler could not issue the warning as it assumed Bitmap
   class (being a template) would not be performing a NO-OP for its default
   constructor. This prevented the "unused variable warning".
  • Loading branch information
cvicentiu committed Feb 9, 2023
1 parent 8dab661 commit 08c8520
Show file tree
Hide file tree
Showing 242 changed files with 1,101 additions and 1,341 deletions.
4 changes: 2 additions & 2 deletions client/mysqlbinlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ class Load_log_processor
}

public:
Load_log_processor() {}
~Load_log_processor() {}
Load_log_processor() = default;
~Load_log_processor() = default;

int init()
{
Expand Down
7 changes: 3 additions & 4 deletions include/ilist.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
// Derive your class from this struct to insert to a linked list.
template <class Tag= void> struct ilist_node
{
ilist_node() noexcept
#ifndef DBUG_OFF
: next(NULL), prev(NULL)
ilist_node() noexcept : next(NULL), prev(NULL) {}
#else
ilist_node() = default;
#endif
{
}

ilist_node(ilist_node *next, ilist_node *prev) noexcept
: next(next), prev(prev)
Expand Down
2 changes: 1 addition & 1 deletion include/my_atomic_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ template <typename Type> class Atomic_relaxed
Atomic_relaxed(const Atomic_relaxed<Type> &rhs)
{ m.store(rhs, std::memory_order_relaxed); }
Atomic_relaxed(Type val) : m(val) {}
Atomic_relaxed() {}
Atomic_relaxed() = default;

operator Type() const { return m.load(std::memory_order_relaxed); }
Type operator=(const Type val)
Expand Down
2 changes: 1 addition & 1 deletion include/my_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template <typename Type> class Atomic_counter
Atomic_counter(const Atomic_counter<Type> &rhs)
{ m_counter.store(rhs, std::memory_order_relaxed); }
Atomic_counter(Type val): m_counter(val) {}
Atomic_counter() {}
Atomic_counter() = default;

Type operator++(int) { return add(1); }
Type operator--(int) { return sub(1); }
Expand Down
2 changes: 1 addition & 1 deletion include/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ template <class ElementType> class span

span(const span &other) : data_(other.data_), size_(other.size_) {}

~span(){};
~span() = default;

span &operator=(const span &other)
{
Expand Down
2 changes: 1 addition & 1 deletion mysys_ssl/my_crypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class MyCTX_nopad : public MyCTX
uchar oiv[MY_AES_BLOCK_SIZE];

MyCTX_nopad() : MyCTX() { }
~MyCTX_nopad() { }
~MyCTX_nopad() = default;

int init(const EVP_CIPHER *cipher, int encrypt, const uchar *key, uint klen,
const uchar *iv, uint ivlen)
Expand Down
8 changes: 2 additions & 6 deletions plugin/handler_socket/handlersocket/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ database::database(const config& c)
{
}

database::~database()
{
}
database::~database() = default;

dbcontext_ptr
database::create_context(bool for_write) volatile
Expand Down Expand Up @@ -226,9 +224,7 @@ dbcontext::dbcontext(volatile database *d, bool for_write)
user_level_lock_timeout = d->get_conf().get_int("wrlock_timeout", 12);
}

dbcontext::~dbcontext()
{
}
dbcontext::~dbcontext() = default;

namespace {

Expand Down
6 changes: 3 additions & 3 deletions plugin/handler_socket/handlersocket/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct dbcontext_i;
typedef std::auto_ptr<dbcontext_i> dbcontext_ptr;

struct database_i {
virtual ~database_i() { }
virtual ~database_i() = default;
virtual dbcontext_ptr create_context(bool for_write) volatile = 0;
virtual void stop() volatile = 0;
virtual const config& get_conf() const volatile = 0;
Expand Down Expand Up @@ -57,7 +57,7 @@ struct prep_stmt {
};

struct dbcallback_i {
virtual ~dbcallback_i () { }
virtual ~dbcallback_i() = default;
virtual void dbcb_set_prep_stmt(size_t pst_id, const prep_stmt& v) = 0;
virtual const prep_stmt *dbcb_get_prep_stmt(size_t pst_id) const = 0;
virtual void dbcb_resp_short(uint32_t code, const char *msg) = 0;
Expand Down Expand Up @@ -111,7 +111,7 @@ struct cmd_exec_args {
};

struct dbcontext_i {
virtual ~dbcontext_i() { }
virtual ~dbcontext_i() = default;
virtual void init_thread(const void *stack_bottom,
volatile int& shutdown_flag) = 0;
virtual void term_thread() = 0;
Expand Down
2 changes: 1 addition & 1 deletion plugin/handler_socket/handlersocket/hstcpsvr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct hstcpsvr_i;
typedef std::auto_ptr<hstcpsvr_i> hstcpsvr_ptr;

struct hstcpsvr_i {
virtual ~hstcpsvr_i() { }
virtual ~hstcpsvr_i() = default;
virtual std::string start_listen() = 0;
static hstcpsvr_ptr create(const config& conf);
};
Expand Down
2 changes: 1 addition & 1 deletion plugin/handler_socket/handlersocket/hstcpsvr_worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct hstcpsvr_worker_arg {
};

struct hstcpsvr_worker_i {
virtual ~hstcpsvr_worker_i() { }
virtual ~hstcpsvr_worker_i() = default;
virtual void run() = 0;
static hstcpsvr_worker_ptr create(const hstcpsvr_worker_arg& arg);
};
Expand Down
2 changes: 1 addition & 1 deletion plugin/handler_socket/libhsclient/hstcpcli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct hstcpcli_i;
typedef std::auto_ptr<hstcpcli_i> hstcpcli_ptr;

struct hstcpcli_i {
virtual ~hstcpcli_i() { }
virtual ~hstcpcli_i() = default;
virtual void close() = 0;
virtual int reconnect() = 0;
virtual bool stable_point() = 0;
Expand Down
2 changes: 1 addition & 1 deletion plugin/handler_socket/libhsclient/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace dena {

/* boost::noncopyable */
struct noncopyable {
noncopyable() { }
noncopyable() = default;
private:
noncopyable(const noncopyable&);
noncopyable& operator =(const noncopyable&);
Expand Down
2 changes: 1 addition & 1 deletion plugin/query_response_time/query_response_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class time_collector

public:
time_collector(utility& u): m_utility(&u) { flush(); }
~time_collector() { }
~time_collector() = default;
uint32_t count(uint index) { return m_count[index]; }
uint64_t total(uint index) { return m_total[index]; }
void flush()
Expand Down
8 changes: 4 additions & 4 deletions plugin/versioning/versioning.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Create_func_trt : public Create_native_func
static Create_func_trt<TRT_FIELD> s_singleton;

protected:
Create_func_trt<TRT_FIELD>() {}
virtual ~Create_func_trt<TRT_FIELD>() {}
Create_func_trt<TRT_FIELD>() = default;
virtual ~Create_func_trt<TRT_FIELD>() = default;
};

template<TR_table::field_id_t TRT_FIELD>
Expand Down Expand Up @@ -131,8 +131,8 @@ class Create_func_trt_trx_sees : public Create_native_func
static Create_func_trt_trx_sees<Item_func_trt_trx_seesX> s_singleton;

protected:
Create_func_trt_trx_sees<Item_func_trt_trx_seesX>() {}
virtual ~Create_func_trt_trx_sees<Item_func_trt_trx_seesX>() {}
Create_func_trt_trx_sees<Item_func_trt_trx_seesX>() = default;
virtual ~Create_func_trt_trx_sees<Item_func_trt_trx_seesX>() = default;
};

template<class X>
Expand Down
2 changes: 1 addition & 1 deletion sql/derived_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class derived_handler
derived_handler(THD *thd_arg, handlerton *ht_arg)
: thd(thd_arg), ht(ht_arg), derived(0),table(0), tmp_table_param(0),
unit(0), select(0) {}
virtual ~derived_handler() {}
virtual ~derived_handler() = default;

/*
Functions to scan data. All these returns 0 if ok, error code in case
Expand Down
8 changes: 2 additions & 6 deletions sql/event_data_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,7 @@ Event_queue_element::Event_queue_element():
SYNOPSIS
Event_queue_element::Event_queue_element()
*/
Event_queue_element::~Event_queue_element()
{
}
Event_queue_element::~Event_queue_element() = default;


/*
Expand All @@ -342,9 +340,7 @@ Event_timed::Event_timed():
Event_timed::~Event_timed()
*/

Event_timed::~Event_timed()
{
}
Event_timed::~Event_timed() = default;


/*
Expand Down
2 changes: 1 addition & 1 deletion sql/event_db_repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Event_parse_data;
class Event_db_repository
{
public:
Event_db_repository(){}
Event_db_repository() = default;

bool
create_event(THD *thd, Event_parse_data *parse_data,
Expand Down
10 changes: 5 additions & 5 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ class Virtual_column_info: public Sql_alloc,
name.length= 0;
};
Virtual_column_info* clone(THD *thd);
~Virtual_column_info() {};
~Virtual_column_info() = default;
enum_vcol_info_type get_vcol_type() const
{
return vcol_type;
Expand Down Expand Up @@ -761,7 +761,7 @@ class Field: public Value_source
Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const LEX_CSTRING *field_name_arg);
virtual ~Field() {}
virtual ~Field() = default;

DTCollation dtcollation() const
{
Expand Down Expand Up @@ -5215,7 +5215,7 @@ class Send_field :public Sql_alloc,
LEX_CSTRING col_name, org_col_name;
ulong length;
uint flags, decimals;
Send_field() {}
Send_field() = default;
Send_field(Field *field)
{
field->make_send_field(this);
Expand Down Expand Up @@ -5320,8 +5320,8 @@ class Copy_field :public Sql_alloc {
Field *from_field,*to_field;
String tmp; // For items

Copy_field() {}
~Copy_field() {}
Copy_field() = default;
~Copy_field() = default;
void set(Field *to,Field *from,bool save); // Field to field
void set(uchar *to,Field *from); // Field to string
void (*do_copy)(Copy_field *);
Expand Down
14 changes: 4 additions & 10 deletions sql/filesort_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,11 @@ class Filesort_buffer
/**
We need an assignment operator, see filesort().
This happens to have the same semantics as the one that would be
generated by the compiler. We still implement it here, to show shallow
assignment explicitly: we have two objects sharing the same array.
generated by the compiler.
Note that this is a shallow copy. We have two objects sharing the same
array.
*/
Filesort_buffer &operator=(const Filesort_buffer &rhs)
{
m_idx_array= rhs.m_idx_array;
m_record_length= rhs.m_record_length;
m_start_of_data= rhs.m_start_of_data;
allocated_size= rhs.allocated_size;
return *this;
}
Filesort_buffer &operator=(const Filesort_buffer &rhs) = default;

private:
typedef Bounds_checked_array<uchar*> Idx_array;
Expand Down
2 changes: 1 addition & 1 deletion sql/gcalc_slicescan.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class Gcalc_shape_transporter
{
return complete_ring() || complete_poly();
}
virtual ~Gcalc_shape_transporter() {}
virtual ~Gcalc_shape_transporter() = default;
};


Expand Down
2 changes: 1 addition & 1 deletion sql/group_by_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class group_by_handler

group_by_handler(THD *thd_arg, handlerton *ht_arg)
: thd(thd_arg), ht(ht_arg), table(0) {}
virtual ~group_by_handler() {}
virtual ~group_by_handler() = default;

/*
Functions to scan data. All these returns 0 if ok, error code in case
Expand Down
24 changes: 12 additions & 12 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ struct xid_t {
long bqual_length;
char data[XIDDATASIZE]; // not \0-terminated !

xid_t() {} /* Remove gcc warning */
xid_t() = default; /* Remove gcc warning */
bool eq(struct xid_t *xid) const
{ return !xid->is_null() && eq(xid->gtrid_length, xid->bqual_length, xid->data); }
bool eq(long g, long b, const char *d) const
Expand Down Expand Up @@ -1529,7 +1529,7 @@ struct handlerton
public:
virtual bool add_table(const char *tname, size_t tlen) = 0;
virtual bool add_file(const char *fname) = 0;
protected: virtual ~discovered_list() {}
protected: virtual ~discovered_list() = default;
};

/*
Expand Down Expand Up @@ -1710,7 +1710,7 @@ struct THD_TRANS
m_unsafe_rollback_flags= 0;
}
bool is_empty() const { return ha_list == NULL; }
THD_TRANS() {} /* Remove gcc warning */
THD_TRANS() = default; /* Remove gcc warning */

unsigned int m_unsafe_rollback_flags;
/*
Expand Down Expand Up @@ -1954,7 +1954,7 @@ struct Table_period_info: Sql_alloc

struct start_end_t
{
start_end_t() {};
start_end_t() = default;
start_end_t(const LEX_CSTRING& _start, const LEX_CSTRING& _end) :
start(_start),
end(_end) {}
Expand Down Expand Up @@ -2262,9 +2262,9 @@ struct Table_specification_st: public HA_CREATE_INFO,
class inplace_alter_handler_ctx : public Sql_alloc
{
public:
inplace_alter_handler_ctx() {}
inplace_alter_handler_ctx() = default;

virtual ~inplace_alter_handler_ctx() {}
virtual ~inplace_alter_handler_ctx() = default;
virtual void set_shared_data(const inplace_alter_handler_ctx& ctx) {}
};

Expand Down Expand Up @@ -2490,8 +2490,8 @@ typedef struct st_key_create_information
class TABLEOP_HOOKS
{
public:
TABLEOP_HOOKS() {}
virtual ~TABLEOP_HOOKS() {}
TABLEOP_HOOKS() = default;
virtual ~TABLEOP_HOOKS() = default;

inline void prelock(TABLE **tables, uint count)
{
Expand Down Expand Up @@ -2532,7 +2532,7 @@ typedef class Item COND;

typedef struct st_ha_check_opt
{
st_ha_check_opt() {} /* Remove gcc warning */
st_ha_check_opt() = default; /* Remove gcc warning */
uint flags; /* isam layer flags (e.g. for myisamchk) */
uint sql_flags; /* sql layer flags - for something myisamchk cannot do */
time_t start_time; /* When check/repair starts */
Expand Down Expand Up @@ -2911,8 +2911,8 @@ uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map);
class Handler_share
{
public:
Handler_share() {}
virtual ~Handler_share() {}
Handler_share() = default;
virtual ~Handler_share() = default;
};

enum class Compare_keys : uint32_t
Expand Down Expand Up @@ -4969,7 +4969,7 @@ class Discovered_table_list: public handlerton::discovered_list
const LEX_CSTRING *wild_arg);
Discovered_table_list(THD *thd_arg, Dynamic_array<LEX_CSTRING*> *tables_arg)
: thd(thd_arg), wild(NULL), with_temps(true), tables(tables_arg) {}
~Discovered_table_list() {}
~Discovered_table_list() = default;

bool add_table(const char *tname, size_t tlen);
bool add_file(const char *fname);
Expand Down
2 changes: 1 addition & 1 deletion sql/hash_filo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class hash_filo_element
private:
hash_filo_element *next_used,*prev_used;
public:
hash_filo_element() {}
hash_filo_element() = default;
hash_filo_element *next()
{ return next_used; }
hash_filo_element *prev()
Expand Down
Loading

0 comments on commit 08c8520

Please sign in to comment.