Skip to content

Commit

Permalink
PS-9504: Replace MY_NODISCARD with [[nodiscard]]
Browse files Browse the repository at this point in the history
We require at least gcc 7.1 or clang 5 for compilation which both support `[[nodiscard]]`.
`MY_NODISCARD` is no longer needed.
  • Loading branch information
inikep committed Nov 18, 2024
1 parent 66b2a91 commit bbb678b
Show file tree
Hide file tree
Showing 29 changed files with 70 additions and 84 deletions.
14 changes: 0 additions & 14 deletions include/my_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ constexpr bool unlikely(bool expr) { return expr; }
#define __func__ __FUNCTION__
#endif

#if defined(__cplusplus) && defined(__cpp_attributes) && \
defined(__has_cpp_attribute)
#if __has_cpp_attribute(nodiscard)
#define MY_NODISCARD [[nodiscard]]
#elif __has_cpp_attribute(gnu::warn_unused_result)
#define MY_NODISCARD [[gnu::warn_unused_result]]
#endif /* __has_cpp_attribute(gnu::warn_unused_result) */
#endif /* defined(__cplusplus) && defined(__cpp_attributes) && \
defined(__has_cpp_attribute) */

/*
Disable MY_ATTRIBUTE for Sun Studio and Visual Studio.
Note that Sun Studio supports some __attribute__ variants,
Expand All @@ -120,10 +110,6 @@ constexpr bool unlikely(bool expr) { return expr; }
#define ALWAYS_INLINE __attribute__((always_inline)) inline
#endif

#ifndef MY_NODISCARD
#define MY_NODISCARD MY_ATTRIBUTE((warn_unused_result))
#endif /* MY_NODISCARD */

#if defined(_MSC_VER)
#define NO_INLINE __declspec(noinline)
#else
Expand Down
24 changes: 12 additions & 12 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,30 +521,30 @@ inline int my_b_get(IO_CACHE *info) {
return _my_b_get(info);
}

MY_NODISCARD
[[nodiscard]]
inline my_off_t my_b_tell(const IO_CACHE *info) {
return info->pos_in_file + *info->current_pos - info->request_pos;
}

MY_NODISCARD
[[nodiscard]]
inline uchar *my_b_get_buffer_start(const IO_CACHE *info) {
return info->request_pos;
}

MY_NODISCARD
[[nodiscard]]
inline size_t my_b_get_bytes_in_buffer(const IO_CACHE *info) {
return info->read_end - my_b_get_buffer_start(info);
}

MY_NODISCARD
[[nodiscard]]
inline my_off_t my_b_get_pos_in_file(const IO_CACHE *info) {
return info->pos_in_file;
}

/* tell write offset in the SEQ_APPEND cache */
int my_b_copy_to_file(IO_CACHE *cache, FILE *file);

MY_NODISCARD
[[nodiscard]]
inline size_t my_b_bytes_in_cache(const IO_CACHE *info) {
return *info->current_end - *info->current_pos;
}
Expand Down Expand Up @@ -740,31 +740,31 @@ extern bool array_append_string_unique(const char *str, const char **array,

void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
MY_NODISCARD
[[nodiscard]]
extern int init_io_cache_ext(IO_CACHE *info, File file, size_t cachesize,
enum cache_type type, my_off_t seek_offset,
bool use_async_io, myf cache_myflags,
PSI_file_key file_key);
MY_NODISCARD
[[nodiscard]]
extern int init_io_cache(IO_CACHE *info, File file, size_t cachesize,
enum cache_type type, my_off_t seek_offset,
bool use_async_io, myf cache_myflags);
MY_NODISCARD
[[nodiscard]]
extern bool reinit_io_cache(IO_CACHE *info, enum cache_type type,
my_off_t seek_offset, bool use_async_io,
bool clear_cache);
extern void setup_io_cache(IO_CACHE *info);
MY_NODISCARD
[[nodiscard]]
extern int _my_b_read(IO_CACHE *info, uchar *Buffer, size_t Count);
MY_NODISCARD
[[nodiscard]]
extern int _my_b_read_r(IO_CACHE *info, uchar *Buffer, size_t Count);
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
IO_CACHE *write_cache, uint num_threads);
extern void remove_io_thread(IO_CACHE *info);
MY_NODISCARD
[[nodiscard]]
extern int _my_b_seq_read(IO_CACHE *info, uchar *Buffer, size_t Count);
extern int _my_b_net_read(IO_CACHE *info, uchar *Buffer, size_t Count);
MY_NODISCARD
[[nodiscard]]
extern int _my_b_write(IO_CACHE *info, const uchar *Buffer, size_t Count);
extern int my_b_append(IO_CACHE *info, const uchar *Buffer, size_t Count);
extern int my_b_safe_write(IO_CACHE *info, const uchar *Buffer, size_t Count);
Expand Down
10 changes: 5 additions & 5 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5334,7 +5334,7 @@ class handler {
*/

virtual bool is_ignorable_error(int error);
MY_NODISCARD virtual bool continue_partition_copying_on_error(
[[nodiscard]] virtual bool continue_partition_copying_on_error(
int error [[maybe_unused]]) {
return false;
}
Expand Down Expand Up @@ -6558,7 +6558,7 @@ class handler {
@brief Offload an update to the storage engine. See handler::fast_update()
for details.
*/
MY_NODISCARD int ha_fast_update(THD *thd,
[[nodiscard]] int ha_fast_update(THD *thd,
mem_root_deque<Item *> &update_fields,
mem_root_deque<Item *> &update_values,
Item *conds);
Expand All @@ -6567,7 +6567,7 @@ class handler {
@brief Offload an upsert to the storage engine. See handler::upsert()
for details.
*/
MY_NODISCARD int ha_upsert(THD *thd, mem_root_deque<Item *> &update_fields,
[[nodiscard]] int ha_upsert(THD *thd, mem_root_deque<Item *> &update_fields,
mem_root_deque<Item *> &update_values);

private:
Expand All @@ -6590,7 +6590,7 @@ class handler {
@note HA_READ_BEFORE_WRITE_REMOVAL flag doesn not fit there because
handler::ha_update_row(...) does not accept conditions.
*/
MY_NODISCARD virtual int fast_update(THD *, mem_root_deque<Item *> &,
[[nodiscard]] virtual int fast_update(THD *, mem_root_deque<Item *> &,
mem_root_deque<Item *> &, Item *) {
return ENOTSUP;
}
Expand All @@ -6611,7 +6611,7 @@ class handler {
@return an error if the insert should be terminated.
*/
MY_NODISCARD virtual int upsert(THD *, mem_root_deque<Item *> &,
[[nodiscard]] virtual int upsert(THD *, mem_root_deque<Item *> &,
mem_root_deque<Item *> &) {
return ENOTSUP;
}
Expand Down
2 changes: 1 addition & 1 deletion sql/partition_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ static inline void init_all_partitions_iterator(partition_info *part_info,
@return true - On failure.
@return false - On success.
*/
MY_NODISCARD
[[nodiscard]]
bool fill_first_partition_name(const partition_info *part_info,
const char *normalized_path, char *first_name);

Expand Down
2 changes: 1 addition & 1 deletion sql/set_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ collation_unordered_map<std::string, sys_var *>
extern bool get_sysvar_source(const char *name, uint length,
enum enum_variable_source *source);

MY_NODISCARD
[[nodiscard]]
int sql_set_variables(THD *thd, List<set_var_base> *var_list, bool opened);
bool keyring_access_test();
bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type);
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static bool is_name_in_list(const char *name, List<String> list_names) {
false Success
*/

MY_NODISCARD
[[nodiscard]]
static bool partition_default_handling(Partition_handler *part_handler,
partition_info *part_info,
bool is_create_table_ind,
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void get_full_part_id_from_key(const TABLE *table, uchar *buf, KEY *key_info,
@retval true - On failure.
@retval false - On success.
*/
MY_NODISCARD
[[nodiscard]]
bool get_first_partition_name(THD *thd, Partition_handler *part_handler,
const char *normalized_path,
const char *partition_info_str,
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/handler/ha_innodb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ will be closed before the index creation/drop.
@param[in,out] share share structure where index translation table
will be constructed in.
@return true if index translation table built successfully */
MY_NODISCARD
[[nodiscard]]
bool innobase_build_index_translation(const TABLE *table,
dict_table_t *ib_table,
INNOBASE_SHARE *share);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/buf0flu.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
bool buf_flush_page_cleaner_is_active();

/** Returns the count of currently active LRU manager threads. */
MY_NODISCARD size_t buf_flush_active_lru_managers() noexcept;
[[nodiscard]] size_t buf_flush_active_lru_managers() noexcept;

#ifdef UNIV_DEBUG

Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/data0data.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ occupied by the field structs or the tuple struct is not counted.
@param[in] tuple typed data tuple
@param[in] comp nonzero=ROW_FORMAT=COMPACT
@return sum of data lens */
MY_NODISCARD
[[nodiscard]]
static inline ulint dtuple_get_data_size(const dtuple_t *tuple, ulint comp);
/** Compare two data tuples.
@param[in] tuple1 first data tuple
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/include/dict0crea.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static const constexpr auto ZIP_DICT_MAX_DATA_LENGTH = 32506;
@param[out] dict_id dict id
@param[in,out] trx transaction
@return error code or DB_SUCCESS */
MY_NODISCARD
[[nodiscard]]
dberr_t dict_create_get_zip_dict_id_by_reference(table_id_t table_id,
ulint column_pos,
ulint *dict_id, trx_t *trx);
Expand All @@ -134,7 +134,7 @@ Must be freed with my_free().
@param[out] data_len dict data length
@param[in,out] trx transaction
@return error code or DB_SUCCESS */
MY_NODISCARD
[[nodiscard]]
dberr_t dict_create_get_zip_dict_info_by_id(ulint dict_id, char **name,
ulint *name_len, char **data,
ulint *data_len, trx_t *trx);
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/include/dict0dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ extern bool dict_upgrade_zip_dict_missing;
@param[out] dict_id zip_dict id
@retval DB_SUCCESS if OK
@retval DB_RECORD_NOT_FOUND if not found */
MY_NODISCARD
[[nodiscard]]
dberr_t dict_get_dictionary_id_by_key(table_id_t table_id, ulint column_pos,
ulint *dict_id);

Expand All @@ -1696,7 +1696,7 @@ Must be freed with mem_free().
@param[out] data_len dictionary data length
@retval DB_SUCCESS if OK
@retval DB_RECORD_NOT_FOUND if not found */
MY_NODISCARD
[[nodiscard]]
dberr_t dict_get_dictionary_info_by_id(ulint dict_id, char **name,
ulint *name_len, char **data,
ulint *data_len);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/dict0load.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ information from the record and returns to caller.
@param[out] data dict data
@param[out] data_len dict data length
@return error message, or NULL on success */
MY_NODISCARD
[[nodiscard]]
const char *dict_process_sys_zip_dict(mem_heap_t *heap,
const dict_index_t &index,
const rec_t *rec, ulint *id,
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/fil0fil.h
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ inline void fil_space_open_if_needed(fil_space_t *space) {
/** Enable encryption of temporary tablespace
@param[in,out] space tablespace object
@return DB_SUCCESS on success, DB_ERROR on failure */
MY_NODISCARD
[[nodiscard]]
dberr_t fil_temp_update_encryption(fil_space_t *space);

#if !defined(NO_FALLOCATE) && defined(UNIV_LINUX)
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/fsp0fsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ uint32_t fsp_flags_to_dict_tf(uint32_t fsp_flags, bool compact);
/** Enable encryption for already existing tablespace.
@param[in,out] space tablespace object
@return true if success, else false */
MY_NODISCARD
[[nodiscard]]
bool fsp_enable_encryption(fil_space_t *space);

/** Calculates the descriptor index within a descriptor page.
Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/include/ha_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void thd_set_lock_wait_time(THD *thd,
/** Is FT ignore stopwords variable set.
@param thd Thread object
@return true if ft_ignore_stopwords is set, false otherwise. */
MY_NODISCARD
[[nodiscard]]
bool thd_has_ft_ignore_stopwords(THD *thd) noexcept;

/** Get the value of innodb_tmpdir.
Expand Down Expand Up @@ -448,13 +448,13 @@ void innobase_commit_low(trx_t *trx);

/** Get the transaction of the current connection handle, if either exists.
@return transaction of the current connection handle or NULL. */
MY_NODISCARD
[[nodiscard]]
trx_t *innobase_get_trx(void);

/** Get the transaction of the current connection handle if slow query log
InnoDB extended statistics should be collected.
@return transaction object if statistics should be collected, or NULL. */
MY_NODISCARD
[[nodiscard]]
trx_t *innobase_get_trx_for_slow_log(void) noexcept;

extern bool innodb_inited;
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/include/os0enc.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Encryption {
specified explicitly
@param[in] algorithm Encryption algorithm to check
@return true if no algorithm explicitly requested */
MY_NODISCARD static bool none_explicitly_specified(
[[nodiscard]] static bool none_explicitly_specified(
bool explicit_encryption, const char *algorithm) noexcept;

/** Generate random encryption value for key and iv.
Expand Down Expand Up @@ -379,7 +379,7 @@ class Encryption {
byte *tmp, ulint tmp_len) const noexcept;

/** Check if keyring plugin loaded. */
MY_NODISCARD static bool check_keyring() noexcept;
[[nodiscard]] static bool check_keyring() noexcept;

/** Get encryption type
@return encryption type **/
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/os0file.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class IORequest {
}

/** @return true if the page write should not be encrypted */
MY_NODISCARD bool is_encryption_disabled() const noexcept {
[[nodiscard]] bool is_encryption_disabled() const noexcept {
return ((m_type & NO_ENCRYPTION) != 0);
}

Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/include/os0thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ using Atomic_xor_of_thread_id =
thread. On Linux, returns tid. On other systems currently returns
os_thread_get_curr_id().
@return current thread identifier */
MY_NODISCARD os_tid_t os_thread_get_tid() noexcept;
[[nodiscard]] os_tid_t os_thread_get_tid() noexcept;

/** Set relative scheduling priority for a given thread on
Linux. Currently a no-op on other systems.
@param[in] thread_id thread id
@param[in] relative_priority system-specific priority value
@return An actual thread priority after the update */
MY_NODISCARD
[[nodiscard]]
unsigned long int os_thread_set_priority(
os_tid_t thread_id, unsigned long int relative_priority) noexcept;

Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/include/row0log.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ ulint row_log_estimate_work(const dict_index_t *index);

/** Find out if temporary log files encrypted.
@return true if temporary log file should be encrypted, false if not */
MY_NODISCARD
[[nodiscard]]
bool log_tmp_is_encrypted() noexcept;

/** Check the row log encryption is enabled or not.
Expand All @@ -226,7 +226,7 @@ void log_tmp_enable_encryption_if_set();
@param[in] offs offset to block
@param[in] space_id tablespace id
@return whether the operation succeeded */
MY_NODISCARD
[[nodiscard]]
bool log_tmp_block_encrypt(const byte *src_block, ulint size, byte *dst_block,
os_offset_t offs, space_id_t space_id);

Expand All @@ -237,7 +237,7 @@ bool log_tmp_block_encrypt(const byte *src_block, ulint size, byte *dst_block,
@param[in] offs offset to block
@param[in] space_id tablespace id
@return whether the operation succeeded */
MY_NODISCARD
[[nodiscard]]
bool log_tmp_block_decrypt(const byte *src_block, ulint size, byte *dst_block,
os_offset_t offs, space_id_t space_id);

Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/include/row0mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void row_mysql_prebuilt_free_compress_heap(row_prebuilt_t *prebuilt) noexcept;
@param[in] dict_data_len optional dictionary data length
@param[in] compress_heap
@return pointer to the uncompressed data */
MY_NODISCARD
[[nodiscard]]
const byte *row_decompress_column(const byte *data, ulint *len,
const byte *dict_data, ulint dict_data_len,
mem_heap_t **compress_heap);
Expand All @@ -126,7 +126,7 @@ const byte *row_decompress_column(const byte *data, ulint *len,
@param[in] dict_data_len optional dictionary data length
@param[in] compress_heap
@return pointer to the compressed data */
MY_NODISCARD
[[nodiscard]]
byte *row_compress_column(const byte *data, ulint *len, ulint lenlen,
const byte *dict_data, ulint dict_data_len,
mem_heap_t **compress_heap);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/srv0srv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ void srv_master_thread_disabled_debug_update(THD *thd, SYS_VAR *var,
innodb_temp_tablespace_encrypt is TRUE
@param[in] enable true to enable encryption, false to disable
@return DB_SUCCESS on success, DB_ERROR on failure */
MY_NODISCARD
[[nodiscard]]
dberr_t srv_temp_encryption_update(bool enable);

/** Status variables to be passed to MySQL */
Expand Down
Loading

0 comments on commit bbb678b

Please sign in to comment.