Skip to content

Commit 138489f

Browse files
author
Tor Didriksen
committed
Bug#35362952 Prepare the codebase for C++20
At some point in the future, we will most likely want to switch from C++17 to C++20. Prepare the codebase for this, by rewriting it to be valid for both C++17 and C++20. Details: ================ All member functions Foo::operator==(const Foo&) must be const. Otherwise Clang will complain: ISO C++20 considers use of overloaded operator '==' .... to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator] ================ ICU cannot be built with -std=c++20 It has a homegrown type typedef int8_t UBool; and there are plenty of warnings like: return type of virtual UBool icu_69::TimeArrayTimeZoneRule::operator==(const icu_69::TimeZoneRule&) const is not bool and there is no warning to disable, operator==() *must* return bool. The solution is to downgrade to -std=c++17 when building ICU. ================ Several warnings of the type: increment of object of volatile-qualified type 'volatile int32' (aka 'volatile int') is deprecated [-Werror,-Wdeprecated-volatile] or alternatively volatile-qualified type is deprecated [-Werror=volatile] Most of these volatile variables should be converted to std::atomic<> but some cannot, if they are members of classes which need copy construction, or copy assignment. ================ Both clang and gcc say: pfs_example_continent.cc:273:50: error: no match for operator= (operand types are PFS_engine_table_proxy and <brace-enclosed initializer list>) The solution is to remove the default CTOR of PFS_engine_table_proxy. ================ scheduler_imp.cc:420:49: error: memory_order_acquire is not a member of std::memory_order ================ Template arguments should not be repeated in CTORs/DTORs error: expected unqualified-id before ) token 287 | Lockless_hash<T>(); ================ package <utility> for gcc12, which an in_range() function. The macro is unused, so just remove it. ================ clang complains: router/src/harness/include/mysql/harness/net_ts/executor.h:173:46: error: member access into incomplete type 'net::execution_context::service The solution is to move the implementation of a couple of member functions later in the same source file. ================ error: no matching function for call to object of type '(lambda at router/src/http/tests/test_passwd.cc:100:19) router/src/http/tests/test_passwd.cc:100:19: note: candidate function not viable: expects an lvalue for 1st argument ================ in sql/auth/sql_authorization.cc move some 'bool operator==()' functions up so they are visible when we do find(granted_roles.begin(), granted_roles.end(), role_id) ================ sql/field.cc:5570:22: warning: comparison of floating-point type double with enumeration type Field_year::Limits is deprecated [-Wdeprecated-enum-float-conversion] Add explicit static_cast. ================ log_event.cc make slave_skip_counter std::atomic implicit capture of 'this' via [=] is deprecated in C++20 [-Wdeprecated] Make an explicit list of captured variables instead. ================ sql_bitmap.h do not repeat template parameters in CTOR/DTOR ================ sql_lex.h sql/sql_lex.h:2860:45: error: arithmetic between different enumeration types ('Query_tables_list::enum_binlog_stmt_unsafe' and 'Query_tables_list::enum_binlog_stmt_type') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion] ================ Misc places in storage/innobase implicit capture of 'this' via [=] is deprecated in C++20 [-Wdeprecated] ================ gcc12 complains about test_net_ts_timer.cc:144:36: error: redefinition of 'template<class CharT, class Traits, class Rep, class Period> std::basic_ostream<_CharT, _Traits>& std::chrono::operator<<(std::basic_ostream<_CharT, _Traits>&, const duration<_Rep2, _Period2>&)' The fix is to change the feature test. ================ clang on loki09: plugin/data_masking/datamask.cc:27:13: error: instantiation of variable 'datamasking::Generator<std::basic_string<char>>::REGISTRY' required here, but no definition is available [-Werror,-Wundefined-var-template] switch (REGISTRY.has(token.get_blacklist(), ctx.m_in)) { the fix is to move implementation of Generator<T>::generate(const Dictionary_token<T> &token, Context<T> &ctx) to plugin/data_masking/udf/functions.cc ================ clang 13/14 on Linux: sql/log_event.cc:7964:15: error: explicit capture of 'this' with a capture default of '=' is a C++20 extension [-Werror,-Wc++20-extensions] [=, this](TABLE const *table, size_t column_index) -> bool ================ strings_strnxfrm-t.cc error: invalid conversion from const char8_t* to const char* Change-Id: I51c24560bb72c071996fc2f4d85c5506fac523b5
1 parent c27025a commit 138489f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+416
-236
lines changed

CMakeLists.txt

+27
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,33 @@ IF(WITH_DEFAULT_COMPILER_OPTIONS)
789789
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/build_configurations/compiler_options.cmake)
790790
ENDIF()
791791

792+
OPTION(WITH_EXPERIMENTAL_CPP20
793+
"Build with -std=c++20, note: this is experimental" OFF)
794+
795+
IF(WITH_EXPERIMENTAL_CPP20)
796+
IF(MY_COMPILER_IS_GNU)
797+
IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
798+
MESSAGE(FATAL_ERROR "GCC 10 or newer is required for -std=c++20")
799+
ENDIF()
800+
ELSEIF(MY_COMPILER_IS_CLANG)
801+
IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0)
802+
MESSAGE(FATAL_ERROR "Clang 11 or newer is required for -std=c++20")
803+
ENDIF()
804+
ENDIF()
805+
IF(UNIX)
806+
STRING(REPLACE "-std=c++17" "-std=c++20"
807+
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
808+
ELSE()
809+
FOREACH(flag
810+
CMAKE_CXX_FLAGS_MINSIZEREL
811+
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
812+
CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT
813+
)
814+
STRING(REPLACE "/std:c++17" "/std:c++20" ${flag} "${${flag}}")
815+
ENDFOREACH()
816+
ENDIF()
817+
ENDIF()
818+
792819
# Assume, for now at least, that we want build-id for all kinds of Linux builds.
793820
IF(LINUX)
794821
OPTION(WITH_BUILD_ID "Add --build-id=sha1 to all executables." ON)

components/keyrings/common/data/data.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void Data::set_type(Type type) {
8888
}
8989

9090
/** Comparison */
91-
bool Data::operator==(const Data &other) {
91+
bool Data::operator==(const Data &other) const {
9292
return data_ == other.data_ && type_ == other.type_ && valid_ == other.valid_;
9393
}
9494

components/keyrings/common/data/data.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Data {
6262

6363
void set_type(Type type);
6464

65-
bool operator==(const Data &other);
65+
bool operator==(const Data &other) const;
6666

6767
protected:
6868
void set_validity();

extra/icu/CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,31 @@ IF(HAS_WARN_FLAG)
129129
LIST(APPEND ICU_LINUX_COMPILE_OPTIONS "${HAS_WARN_FLAG}")
130130
ENDIF()
131131

132+
# typedef int8_t UBool; results in
133+
# error: return type of virtual UBool xxx::operator==(const xxx&) is not bool
134+
IF(CMAKE_CXX_FLAGS MATCHES "-std=c..20")
135+
STRING(REPLACE "-std=c++20" "-std=c++17" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
136+
ENDIF()
137+
138+
IF(WIN32)
139+
# In case we have switched on c++20 elsewhere
140+
FOREACH(flag
141+
CMAKE_CXX_FLAGS_MINSIZEREL
142+
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
143+
CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT
144+
)
145+
IF("${${flag}}" MATCHES "/std:c..20")
146+
STRING(REPLACE "/std:c++20" "/std:c++17" ${flag} "${${flag}}")
147+
ENDIF()
148+
ENDFOREACH()
149+
ENDIF()
150+
151+
# warning: arithmetic between different enumeration types is deprecated
152+
MY_CHECK_CXX_COMPILER_WARNING("-Wdeprecated-enum-enum-conversion" HAS_WARN_FLAG)
153+
IF(HAS_WARN_FLAG)
154+
LIST(APPEND ICU_LINUX_COMPILE_OPTIONS "${HAS_WARN_FLAG}")
155+
ENDIF()
156+
132157
IF(WIN32)
133158
ADD_DEFINITIONS(
134159
-DU_STATIC_IMPLEMENTATION=1

extra/zlib/zlib-1.2.13/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ IF(HAS_MISSING_PROFILE)
156156
ADD_COMPILE_FLAGS(${ZLIB_SRCS} COMPILE_FLAGS ${HAS_MISSING_PROFILE})
157157
ENDIF()
158158

159-
MY_CHECK_CXX_COMPILER_WARNING("-Wdeprecated-non-prototype"
159+
# clang has this, but clang++ does not.
160+
MY_CHECK_C_COMPILER_FLAG("-Wdeprecated-non-prototype"
160161
HAS_DEPRECATED_NON_PROTOTYPE)
161162
IF(HAS_DEPRECATED_NON_PROTOTYPE)
162-
ADD_COMPILE_FLAGS(${ZLIB_SRCS} COMPILE_FLAGS ${HAS_DEPRECATED_NON_PROTOTYPE})
163+
ADD_COMPILE_FLAGS(${ZLIB_SRCS} COMPILE_FLAGS "-Wno-deprecated-non-prototype")
163164
ENDIF()
164165

165166
IF(NOT WIN32)

include/mysql/components/services/log_builtins_filter.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#ifndef LOG_BUILTINS_FILTER_H
2424
#define LOG_BUILTINS_FILTER_H
2525

26+
#include <atomic>
27+
2628
#include <mysql/components/component_implementation.h>
2729
#include <mysql/components/my_service.h>
2830
#include <mysql/components/service_implementation.h>
@@ -138,10 +140,27 @@ typedef struct _log_filter_rule {
138140
ulong flags;
139141

140142
/** how often did this rule match? */
141-
volatile int32 match_count;
143+
std::atomic<int32> match_count;
142144

143145
/** lock an individual rule (to update state keeping) */
144146
mysql_rwlock_t rule_lock;
147+
148+
_log_filter_rule &operator=(const _log_filter_rule &other) {
149+
if (this == &other) return *this;
150+
id = other.id;
151+
jump = other.jump;
152+
match = other.match;
153+
cond = other.cond;
154+
verb = other.verb;
155+
aux = other.aux;
156+
throttle_window_end = other.throttle_window_end;
157+
throttle_window_size = other.throttle_window_size;
158+
throttle_matches = other.throttle_matches;
159+
flags = other.flags;
160+
match_count = other.match_count.load();
161+
rule_lock = other.rule_lock;
162+
return *this;
163+
}
145164
} log_filter_rule;
146165

147166
#define LOG_FILTER_RULE_MAX 512

include/mysql/components/services/pfs_plugin_table_service.h

+15-16
Original file line numberDiff line numberDiff line change
@@ -410,22 +410,21 @@ typedef void (*close_table_t)(PSI_table_handle *handle);
410410
plugin/component.
411411
*/
412412
struct PFS_engine_table_proxy {
413-
rnd_next_t rnd_next;
414-
rnd_init_t rnd_init;
415-
rnd_pos_t rnd_pos;
416-
index_init_t index_init;
417-
index_read_t index_read;
418-
index_next_t index_next;
419-
read_column_value_t read_column_value;
420-
reset_position_t reset_position;
421-
write_column_value_t write_column_value;
422-
write_row_values_t write_row_values;
423-
update_column_value_t update_column_value;
424-
update_row_values_t update_row_values;
425-
delete_row_values_t delete_row_values;
426-
open_table_t open_table;
427-
close_table_t close_table;
428-
PFS_engine_table_proxy() = default;
413+
rnd_next_t rnd_next{nullptr};
414+
rnd_init_t rnd_init{nullptr};
415+
rnd_pos_t rnd_pos{nullptr};
416+
index_init_t index_init{nullptr};
417+
index_read_t index_read{nullptr};
418+
index_next_t index_next{nullptr};
419+
read_column_value_t read_column_value{nullptr};
420+
reset_position_t reset_position{nullptr};
421+
write_column_value_t write_column_value{nullptr};
422+
write_row_values_t write_row_values{nullptr};
423+
update_column_value_t update_column_value{nullptr};
424+
update_row_values_t update_row_values{nullptr};
425+
delete_row_values_t delete_row_values{nullptr};
426+
open_table_t open_table{nullptr};
427+
close_table_t close_table{nullptr};
429428
};
430429
typedef struct PFS_engine_table_proxy PFS_engine_table_proxy;
431430

include/mysql/service_rules_table.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Cursor {
113113
Equality operator. The only cursors that are equal are past-the-end
114114
cursors.
115115
*/
116-
bool operator==(const Cursor &other) {
116+
bool operator==(const Cursor &other) const {
117117
return (m_is_finished == other.m_is_finished);
118118
}
119119

plugin/audit_null/audit_null.cc

+33-27
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ static SHOW_VAR simple_status[] = {
161161

162162
{nullptr, nullptr, SHOW_UNDEF, SHOW_SCOPE_GLOBAL}};
163163

164+
static void increment_counter(volatile int *counter) {
165+
int value = *counter;
166+
int new_value = value + 1;
167+
*counter = new_value;
168+
}
169+
164170
/*
165171
Define plugin variables.
166172
*/
@@ -455,24 +461,24 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
455461
bool consume_event = true;
456462

457463
/* prone to races, oh well */
458-
number_of_calls++;
464+
increment_counter(&number_of_calls);
459465

460466
if (event_class == MYSQL_AUDIT_GENERAL_CLASS) {
461467
const struct mysql_event_general *event_general =
462468
(const struct mysql_event_general *)event;
463469

464470
switch (event_general->event_subclass) {
465471
case MYSQL_AUDIT_GENERAL_LOG:
466-
number_of_calls_general_log++;
472+
increment_counter(&number_of_calls_general_log);
467473
break;
468474
case MYSQL_AUDIT_GENERAL_ERROR:
469-
number_of_calls_general_error++;
475+
increment_counter(&number_of_calls_general_error);
470476
break;
471477
case MYSQL_AUDIT_GENERAL_RESULT:
472-
number_of_calls_general_result++;
478+
increment_counter(&number_of_calls_general_result);
473479
break;
474480
case MYSQL_AUDIT_GENERAL_STATUS:
475-
number_of_calls_general_status++;
481+
increment_counter(&number_of_calls_general_status);
476482
break;
477483
default:
478484
break;
@@ -483,16 +489,16 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
483489

484490
switch (event_connection->event_subclass) {
485491
case MYSQL_AUDIT_CONNECTION_CONNECT:
486-
number_of_calls_connection_connect++;
492+
increment_counter(&number_of_calls_connection_connect);
487493
break;
488494
case MYSQL_AUDIT_CONNECTION_DISCONNECT:
489-
number_of_calls_connection_disconnect++;
495+
increment_counter(&number_of_calls_connection_disconnect);
490496
break;
491497
case MYSQL_AUDIT_CONNECTION_CHANGE_USER:
492-
number_of_calls_connection_change_user++;
498+
increment_counter(&number_of_calls_connection_change_user);
493499
break;
494500
case MYSQL_AUDIT_CONNECTION_PRE_AUTHENTICATE:
495-
number_of_calls_connection_pre_authenticate++;
501+
increment_counter(&number_of_calls_connection_pre_authenticate);
496502
break;
497503
default:
498504
break;
@@ -503,10 +509,10 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
503509

504510
switch (event_parse->event_subclass) {
505511
case MYSQL_AUDIT_PARSE_PREPARSE:
506-
number_of_calls_parse_preparse++;
512+
increment_counter(&number_of_calls_parse_preparse);
507513
break;
508514
case MYSQL_AUDIT_PARSE_POSTPARSE:
509-
number_of_calls_parse_postparse++;
515+
increment_counter(&number_of_calls_parse_postparse);
510516
break;
511517
default:
512518
break;
@@ -558,11 +564,11 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
558564
else if (event_class == MYSQL_AUDIT_SERVER_STARTUP_CLASS) {
559565
/* const struct mysql_event_server_startup *event_startup=
560566
(const struct mysql_event_server_startup *) event; */
561-
number_of_calls_server_startup++;
567+
increment_counter(&number_of_calls_server_startup);
562568
} else if (event_class == MYSQL_AUDIT_SERVER_SHUTDOWN_CLASS) {
563569
/* const struct mysql_event_server_shutdown *event_startup=
564570
(const struct mysql_event_server_shutdown *) event; */
565-
number_of_calls_server_shutdown++;
571+
increment_counter(&number_of_calls_server_shutdown);
566572
} else if (event_class == MYSQL_AUDIT_COMMAND_CLASS) {
567573
const struct mysql_event_command *local_event_command =
568574
(const struct mysql_event_command *)event;
@@ -572,10 +578,10 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
572578

573579
switch (local_event_command->event_subclass) {
574580
case MYSQL_AUDIT_COMMAND_START:
575-
number_of_calls_command_start++;
581+
increment_counter(&number_of_calls_command_start);
576582
break;
577583
case MYSQL_AUDIT_COMMAND_END:
578-
number_of_calls_command_end++;
584+
increment_counter(&number_of_calls_command_end);
579585
break;
580586
default:
581587
break;
@@ -589,16 +595,16 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
589595

590596
switch (event_query->event_subclass) {
591597
case MYSQL_AUDIT_QUERY_START:
592-
number_of_calls_query_start++;
598+
increment_counter(&number_of_calls_query_start);
593599
break;
594600
case MYSQL_AUDIT_QUERY_NESTED_START:
595-
number_of_calls_query_nested_start++;
601+
increment_counter(&number_of_calls_query_nested_start);
596602
break;
597603
case MYSQL_AUDIT_QUERY_STATUS_END:
598-
number_of_calls_query_status_end++;
604+
increment_counter(&number_of_calls_query_status_end);
599605
break;
600606
case MYSQL_AUDIT_QUERY_NESTED_STATUS_END:
601-
number_of_calls_query_nested_status_end++;
607+
increment_counter(&number_of_calls_query_nested_status_end);
602608
break;
603609
default:
604610
break;
@@ -613,16 +619,16 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
613619

614620
switch (event_table->event_subclass) {
615621
case MYSQL_AUDIT_TABLE_ACCESS_INSERT:
616-
number_of_calls_table_access_insert++;
622+
increment_counter(&number_of_calls_table_access_insert);
617623
break;
618624
case MYSQL_AUDIT_TABLE_ACCESS_DELETE:
619-
number_of_calls_table_access_delete++;
625+
increment_counter(&number_of_calls_table_access_delete);
620626
break;
621627
case MYSQL_AUDIT_TABLE_ACCESS_UPDATE:
622-
number_of_calls_table_access_update++;
628+
increment_counter(&number_of_calls_table_access_update);
623629
break;
624630
case MYSQL_AUDIT_TABLE_ACCESS_READ:
625-
number_of_calls_table_access_read++;
631+
increment_counter(&number_of_calls_table_access_read);
626632
break;
627633
default:
628634
break;
@@ -649,10 +655,10 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
649655

650656
switch (event_gvar->event_subclass) {
651657
case MYSQL_AUDIT_GLOBAL_VARIABLE_GET:
652-
number_of_calls_global_variable_get++;
658+
increment_counter(&number_of_calls_global_variable_get);
653659
break;
654660
case MYSQL_AUDIT_GLOBAL_VARIABLE_SET:
655-
number_of_calls_global_variable_set++;
661+
increment_counter(&number_of_calls_global_variable_set);
656662
break;
657663
default:
658664
break;
@@ -699,10 +705,10 @@ static int audit_null_notify(MYSQL_THD thd, mysql_event_class_t event_class,
699705

700706
switch (evt->event_subclass) {
701707
case MYSQL_AUDIT_MESSAGE_INTERNAL:
702-
number_of_calls_message_internal++;
708+
increment_counter(&number_of_calls_message_internal);
703709
break;
704710
case MYSQL_AUDIT_MESSAGE_USER:
705-
number_of_calls_message_user++;
711+
increment_counter(&number_of_calls_message_user);
706712
break;
707713
default:
708714
break;

plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xdr_utils.h

-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ extern "C" u_long xdr_sizeof(xdrproc_t, void *);
5555
x->name##_array_len = 0; \
5656
}
5757

58-
#define in_range(x, name, n) \
59-
(((int)n) >= 0 && ((int)n) < ((int)(x).name##_array_len))
60-
6158
/**
6259
Resize an array
6360
*/

plugin/keyring/digest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void Digest::assign(const char *value) {
5656
is_empty = false;
5757
}
5858

59-
bool Digest::operator==(const Digest &digest) {
59+
bool Digest::operator==(const Digest &digest) const {
6060
return this->is_empty == digest.is_empty && this->length == digest.length &&
6161
memcmp(this->value, digest.value, this->length) == 0;
6262
}

plugin/keyring/digest.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Digest {
4040
~Digest();
4141

4242
void assign(const char *value);
43-
bool operator==(const Digest &digest);
43+
bool operator==(const Digest &digest) const;
4444
Digest &operator=(const Digest &digest);
4545
void compute(uchar *memory, size_t memory_size);
4646

0 commit comments

Comments
 (0)