Skip to content

Commit

Permalink
Bug #34597862 Use standard C++ attributes rather than MY_ATTRIBUTE
Browse files Browse the repository at this point in the history
Use standard C++ attributes, which are visible/valid for all compilers:

- [[noreturn]] rather than MY_ATTRIBUTE((noreturn))
- [[maybe_unused]] rather than MY_ATTRIBUTE(maybe_unused))

Change-Id: Iaffa74a062dc8183ae6aff9ba214376658327973
(cherry picked from commit f49bd7d6c7408766b0762a09268e131a49e89b4c)
  • Loading branch information
Tor Didriksen committed Sep 16, 2022
1 parent 1589e51 commit ae5480e
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 49 deletions.
10 changes: 5 additions & 5 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -602,12 +602,12 @@ REPLACE *glob_replace = nullptr;
void replace_strings_append(REPLACE *rep, DYNAMIC_STRING *ds, const char *from,
size_t len);

static void cleanup_and_exit(int exit_code) MY_ATTRIBUTE((noreturn));
[[noreturn]] static void cleanup_and_exit(int exit_code);

void die(const char *fmt, ...) MY_ATTRIBUTE((format(printf, 1, 2)))
MY_ATTRIBUTE((noreturn));
void abort_not_supported_test(const char *fmt, ...)
MY_ATTRIBUTE((format(printf, 1, 2))) MY_ATTRIBUTE((noreturn));
[[noreturn]] void die(const char *fmt, ...)
MY_ATTRIBUTE((format(printf, 1, 2)));
[[noreturn]] void abort_not_supported_test(const char *fmt, ...)
MY_ATTRIBUTE((format(printf, 1, 2)));
void verbose_msg(const char *fmt, ...) MY_ATTRIBUTE((format(printf, 1, 2)));
void log_msg(const char *fmt, ...) MY_ATTRIBUTE((format(printf, 1, 2)));
void flush_ds_res();
Expand Down
4 changes: 2 additions & 2 deletions client/mysqltest/regular_expressions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "m_ctype.h"
#include "my_compiler.h"

extern void die(const char *fmt, ...) MY_ATTRIBUTE((format(printf, 1, 2)))
MY_ATTRIBUTE((noreturn));
[[noreturn]] extern void die(const char *fmt, ...)
MY_ATTRIBUTE((format(printf, 1, 2)));

/*
Filter for queries that can be run using the
Expand Down
2 changes: 1 addition & 1 deletion include/my_dbug.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class AutoDebugTrace {
#ifdef _WIN32
#define DBUG_SUICIDE() DBUG_EXIT()
#else
extern void _db_suicide_() MY_ATTRIBUTE((noreturn));
[[noreturn]] extern void _db_suicide_();
extern void _db_flush_gcov_();
#define DBUG_SUICIDE() (_db_flush_(), _db_suicide_())
#endif
Expand Down
2 changes: 1 addition & 1 deletion mysys/dbug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static char *DbugMalloc(size_t size);
static const char *BaseName(const char *pathname);
static void Indent(CODE_STATE *cs, int indent);
static void DbugFlush(CODE_STATE *);
static void DbugExit(const char *why) MY_ATTRIBUTE((noreturn));
[[noreturn]] static void DbugExit(const char *why);
static const char *DbugStrTok(const char *s);
static void DbugVfprintf(FILE *stream, const char *format, va_list args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,10 @@ static xcom_state_change_cb xcom_comms_cb = nullptr;
static xcom_state_change_cb xcom_exit_cb = nullptr;
static xcom_state_change_cb xcom_expel_cb = nullptr;
static xcom_input_try_pop_cb xcom_try_pop_from_input_cb = nullptr;
static xcom_recovery_cb MY_ATTRIBUTE((unused)) recovery_begin_cb = nullptr;
static xcom_recovery_cb MY_ATTRIBUTE((unused)) recovery_restart_cb = nullptr;
static xcom_recovery_cb MY_ATTRIBUTE((unused)) recovery_init_cb = nullptr;
static xcom_recovery_cb MY_ATTRIBUTE((unused)) recovery_end_cb = nullptr;
[[maybe_unused]] static xcom_recovery_cb recovery_begin_cb = nullptr;
[[maybe_unused]] static xcom_recovery_cb recovery_restart_cb = nullptr;
[[maybe_unused]] static xcom_recovery_cb recovery_init_cb = nullptr;
[[maybe_unused]] static xcom_recovery_cb recovery_end_cb = nullptr;

void set_xcom_run_cb(xcom_state_change_cb x) { xcom_run_cb = x; }
void set_xcom_exit_cb(xcom_state_change_cb x) { xcom_exit_cb = x; }
Expand Down Expand Up @@ -1449,7 +1449,7 @@ static bool_t local_server_is_setup() {
}

static void init_time_queue();
static int paxos_timer_task(task_arg arg MY_ATTRIBUTE((unused)));
static int paxos_timer_task(task_arg arg [[maybe_unused]]);

int xcom_taskmain2(xcom_port listen_port) {
init_xcom_transport(listen_port);
Expand Down Expand Up @@ -3146,7 +3146,7 @@ node_no found_active_leaders(site_def *site) {

/* Check if this message belongs to a channel that should be ignored */
static inline int ignore_message(synode_no x, site_def *site,
char const *dbg MY_ATTRIBUTE((unused))) {
char const *dbg [[maybe_unused]]) {
int retval = !is_active_leader(x.node, site);
IFDBG(D_BASE, STRLIT(dbg); STRLIT(" "); FN; SYCEXP(x); NUMEXP(retval));
return retval;
Expand Down Expand Up @@ -4129,7 +4129,7 @@ struct fp_name {
{ f, #f }

/* List of fp, name pairs */
static struct fp_name MY_ATTRIBUTE((unused)) oblist[] = {
[[maybe_unused]] static struct fp_name oblist[] = {
NAME(x_fetch), NAME(x_execute), NAME(x_terminate), {nullptr, nullptr}};
#undef NAME

Expand Down Expand Up @@ -8660,7 +8660,7 @@ int xcom_client_get_leaders(connection_descriptor *fd, uint32_t group_id,

#if 0
/* Called when leader changes */
static MY_ATTRIBUTE((unused)) xcom_election_cb election_cb = NULL;
[[maybe_unused]] static xcom_election_cb election_cb = NULL;

void set_xcom_election_cb(xcom_election_cb x) { election_cb = x; }
#endif
Expand Down Expand Up @@ -8737,7 +8737,7 @@ static void paxos_timer_advance() {
}

/* Fire any expired timer for a Paxos machine */
static int paxos_timer_task(task_arg arg MY_ATTRIBUTE((unused))) {
static int paxos_timer_task(task_arg arg [[maybe_unused]]) {
DECL_ENV
double start;
ENV_INIT
Expand Down
2 changes: 1 addition & 1 deletion scripts/comp_sql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
FILE *in;
FILE *out;

static void die(const char *fmt, ...) MY_ATTRIBUTE((noreturn))
[[noreturn]] static void die(const char *fmt, ...)
MY_ATTRIBUTE((format(printf, 1, 2)));

static void die(const char *fmt, ...) {
Expand Down
2 changes: 1 addition & 1 deletion sql/auth/sql_mfa.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class I_multi_factor_auth {
column.
*/
virtual bool update_user_attributes() = 0;
virtual void add_factor(I_multi_factor_auth *m MY_ATTRIBUTE((unused))) {}
virtual void add_factor(I_multi_factor_auth *m [[maybe_unused]]) {}
/**
Helper methods to convert this interface into a valid JSON object
and vice versa.
Expand Down
4 changes: 2 additions & 2 deletions sql/server_component/mysql_command_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ bool csi_advanced_command(MYSQL *mysql, enum enum_server_command command,
}

MYSQL_DATA *csi_read_rows(MYSQL *mysql,
MYSQL_FIELD *mysql_fields MY_ATTRIBUTE((unused)),
unsigned int fields MY_ATTRIBUTE((unused))) {
MYSQL_FIELD *mysql_fields [[maybe_unused]],
unsigned int fields [[maybe_unused]]) {
auto mcs_extn = MYSQL_COMMAND_SERVICE_EXTN(mysql);
return std::exchange(mcs_extn->data, nullptr);
}
Expand Down
4 changes: 2 additions & 2 deletions sql/server_component/mysql_command_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ bool csi_advanced_command(MYSQL *mysql, enum enum_server_command command,
MYSQL_ROW csi_fetch_row(MYSQL_RES *);
void csi_flush_use_result(MYSQL *mysql, bool);
MYSQL_DATA *csi_read_rows(MYSQL *mysql,
MYSQL_FIELD *mysql_fields MY_ATTRIBUTE((unused)),
unsigned int fields MY_ATTRIBUTE((unused)));
MYSQL_FIELD *mysql_fields [[maybe_unused]],
unsigned int fields [[maybe_unused]]);
MYSQL_RES *csi_use_result(MYSQL *mysql);
void csi_fetch_lengths(ulong *to, MYSQL_ROW column, unsigned int field_count);
int csi_read_change_user_result(MYSQL *mysql);
Expand Down
2 changes: 1 addition & 1 deletion sql/server_component/mysql_command_delegates.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class Command_delegate {
/*
Session was shutdown while command was running
*/
virtual void shutdown(int flag MY_ATTRIBUTE((unused))) { return; }
virtual void shutdown(int flag [[maybe_unused]]) { return; }

private:
static int call_start_result_metadata(void *ctx, uint num_cols, uint flags,
Expand Down
2 changes: 1 addition & 1 deletion storage/heap/hp_test2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

static int get_options(int argc, char *argv[]);
static int rnd(int max_value);
static void endprog(int sig_number) MY_ATTRIBUTE((noreturn));
[[noreturn]] static void endprog(int sig_number);

static uint flag = 0, verbose = 0, testflag = 0, recant = 10000, silent = 0;
static uint keys = MAX_KEYS;
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/buf/buf0dblwr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ class Reduced_batch_deserializer {
void parse_page_data(const byte *page, uint16_t data_len, F &f) noexcept {
const byte *page_data = page + REDUCED_HEADER_SIZE;
#ifdef UNIV_DEBUG
const byte *page_start MY_ATTRIBUTE((unused)) = page + REDUCED_HEADER_SIZE;
const byte *page_start [[maybe_unused]] = page + REDUCED_HEADER_SIZE;
#endif /* UNIV_DEBUG */
const uint32_t expected_entries = data_len / REDUCED_ENTRY_SIZE;
for (uint32_t entry = 1; entry <= expected_entries; ++entry) {
Expand Down
2 changes: 1 addition & 1 deletion storage/myisam/myisam_ftdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "storage/myisam/myisamdef.h"
#include "welcome_copyright_notice.h"

static void usage() MY_ATTRIBUTE((noreturn));
[[noreturn]] static void usage();
static void complain(int val);
static bool get_one_option(int, const struct my_option *, char *);

Expand Down
3 changes: 1 addition & 2 deletions testclients/mysql_client_fw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ static void print_error(MYSQL *l_mysql, const char *msg);
static void print_st_error(MYSQL_STMT *stmt, const char *msg);
static void client_disconnect(MYSQL *mysql);
static void get_options(int *argc, char ***argv);
static void die(const char *file, int line, const char *expr)
MY_ATTRIBUTE((noreturn));
[[noreturn]] static void die(const char *file, int line, const char *expr);

/*
Abort unless given expression is non-zero.
Expand Down
26 changes: 12 additions & 14 deletions unittest/gunit/xplugin/xcl/protocol_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,21 @@ class Xcl_protocol_impl_tests : public Test {
const int32_t expected_header_size = 5;

EXPECT_CALL(*m_mock_connection, read(_, expected_header_size))
.WillOnce(
Invoke([id, payload_size, error_code](
uchar *data, const std::size_t data_length MY_ATTRIBUTE(
(unused))) -> XError {
// 1byte(type)+ payload_size-bytes(protobuf-msg-payload)
*reinterpret_cast<int32_t *>(data) = 1 + payload_size;
.WillOnce(Invoke([id, payload_size, error_code](
uchar *data, const std::size_t data_length
[[maybe_unused]]) -> XError {
// 1byte(type)+ payload_size-bytes(protobuf-msg-payload)
*reinterpret_cast<int32_t *>(data) = 1 + payload_size;

#ifdef WORDS_BIGENDIAN
std::swap(data[0], data[3]);
std::swap(data[1], data[2]);
std::swap(data[0], data[3]);
std::swap(data[1], data[2]);
#endif

data[4] = static_cast<uchar>(id);
data[4] = static_cast<uchar>(id);

return XError{error_code, ""};
}));
return XError{error_code, ""};
}));
}

template <typename Message_type>
Expand All @@ -209,9 +208,8 @@ class Xcl_protocol_impl_tests : public Test {

EXPECT_CALL(*m_mock_connection, read(_, message_payload.size()))
.WillOnce(
Invoke([message_payload](uchar *data,
const std::size_t data_length MY_ATTRIBUTE(
(unused))) -> XError {
Invoke([message_payload](uchar *data, const std::size_t data_length
[[maybe_unused]]) -> XError {
std::copy(message_payload.begin(), message_payload.end(), data);
return {};
}));
Expand Down
2 changes: 1 addition & 1 deletion unittest/mytap/tap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#define vsnprintf _vsnprintf
#endif

static void handle_core_signal(int signo) MY_ATTRIBUTE((noreturn));
[[noreturn]] static void handle_core_signal(int signo);
static void vemit_tap(int pass, char const *fmt, va_list ap)
MY_ATTRIBUTE((format(printf, 2, 0)));

Expand Down
8 changes: 4 additions & 4 deletions unittest/mytap/tap.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ void diag(char const *fmt, ...) MY_ATTRIBUTE((format(printf, 1, 2)));
@param fmt Bail out message in printf() format.
*/

void BAIL_OUT(char const *fmt, ...)
MY_ATTRIBUTE((noreturn, format(printf, 1, 2)));
[[noreturn]] void BAIL_OUT(char const *fmt, ...)
MY_ATTRIBUTE((format(printf, 1, 2)));

/**
Print summary report and return exit status.
Expand Down Expand Up @@ -268,8 +268,8 @@ int exit_status(void);
around it.
*/

void skip_all(char const *reason, ...)
MY_ATTRIBUTE((noreturn, format(printf, 1, 2)));
[[noreturn]] void skip_all(char const *reason, ...)
MY_ATTRIBUTE((format(printf, 1, 2)));

/**
Start section of tests that are not yet ready.
Expand Down

0 comments on commit ae5480e

Please sign in to comment.