Skip to content

Commit 8cee88a

Browse files
author
Tor Didriksen
committed
Bug #34240108 Remove if __cplusplus > 201100L from public headers
This is a followup to the patch for: Bug #34231639 compile error with the newest Visual studio 2022 where inconsistent such #if __cplusplus tests broke the build. We always build our own code with -std=c++17. However, we cannot assume that client/customer code builds with any specific C++ standard. Remove the : int specifier for enum_field_types. It is the default anyways, and we do not want any difference for C/C++ code. Remove the nullptr initialization of members of 'struct LIST'. This struct is mostly used in legacy code for myisam, and this code does not depend on CTORs or initializers. We also add a which verifies that our public headers do not contain any C++14 or C++17 features. Change-Id: I15b350e09c5d0fa478cde1e74eed240d4d018c0c
1 parent e163f5b commit 8cee88a

File tree

12 files changed

+47
-34
lines changed

12 files changed

+47
-34
lines changed

Diff for: include/CMakeLists.txt

+28
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# along with this program; if not, write to the Free Software
2121
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222

23+
DISABLE_MISSING_PROFILE_WARNING()
24+
2325
# These are the headers required to #include <mysql.h>, which we ship
2426
# to the client as part of our API.
2527
#
@@ -61,3 +63,29 @@ IF (WIN32 AND OPENSSL_APPLINK_C)
6163
COMPONENT Development
6264
)
6365
ENDIF()
66+
67+
SET(INSTALLED_HEADERS_CC ${CMAKE_CURRENT_BINARY_DIR}/installed_headers.cc)
68+
SET(INSTALLED_HEADERS_CONTENT "")
69+
FOREACH(HEADER ${HEADERS} ${HEADERS_MYSQL_DIR})
70+
STRING_APPEND(INSTALLED_HEADERS_CONTENT "#include \"${HEADER}\"")
71+
STRING_APPEND(INSTALLED_HEADERS_CONTENT "\n")
72+
ENDFOREACH()
73+
STRING_APPEND(INSTALLED_HEADERS_CONTENT
74+
"int main(int, char **) { return 0; }"
75+
)
76+
77+
CONFIGURE_FILE_CONTENT("${INSTALLED_HEADERS_CONTENT}"
78+
${INSTALLED_HEADERS_CC}
79+
)
80+
81+
# Verifies that all installed headers comply with -std=c++11
82+
# i.e. no c++17 features used.
83+
# VS/clang on windows do not accept /std:c++11
84+
MYSQL_ADD_EXECUTABLE(installed_headers
85+
${INSTALLED_HEADERS_CC}
86+
DEPENDENCIES GenError
87+
SKIP_INSTALL
88+
)
89+
# This will add -std=gnu++11 for compilers which support it.
90+
# It will be silently ignored on Windows.
91+
SET_PROPERTY(TARGET installed_headers PROPERTY CXX_STANDARD 11)

Diff for: include/field_types.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ extern "C" {
4949
/**
5050
Column types for MySQL
5151
*/
52-
enum enum_field_types
53-
#if defined(__cplusplus)
54-
// N2764: Forward enum declarations, added in C++11
55-
: int
56-
#endif /* __cplusplus */
57-
{ MYSQL_TYPE_DECIMAL,
52+
enum enum_field_types {
53+
MYSQL_TYPE_DECIMAL,
5854
MYSQL_TYPE_TINY,
5955
MYSQL_TYPE_SHORT,
6056
MYSQL_TYPE_LONG,
@@ -87,7 +83,8 @@ enum enum_field_types
8783
MYSQL_TYPE_BLOB = 252,
8884
MYSQL_TYPE_VAR_STRING = 253,
8985
MYSQL_TYPE_STRING = 254,
90-
MYSQL_TYPE_GEOMETRY = 255 };
86+
MYSQL_TYPE_GEOMETRY = 255
87+
};
9188

9289
#ifdef __cplusplus
9390
} // extern "C"

Diff for: include/my_list.h

+3-8
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,16 @@
2525
along with this program; if not, write to the Free Software
2626
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2727

28-
#ifndef _list_h_
29-
#define _list_h_
28+
#ifndef MY_LIST_INCLUDED
29+
#define MY_LIST_INCLUDED
3030

3131
/**
3232
@file include/my_list.h
3333
*/
3434

3535
typedef struct LIST {
36-
#if defined(__cplusplus) && __cplusplus >= 201103L
37-
struct LIST *prev{nullptr}, *next{nullptr};
38-
void *data{nullptr};
39-
#else
4036
struct LIST *prev, *next;
4137
void *data;
42-
#endif
4338
} LIST;
4439

4540
typedef int (*list_walk_action)(void *, void *);
@@ -54,4 +49,4 @@ extern int list_walk(LIST *, list_walk_action action, unsigned char *argument);
5449

5550
#define list_rest(a) ((a)->next)
5651

57-
#endif
52+
#endif // MY_LIST_INCLUDED

Diff for: include/my_time.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@
4848
#include <winsock2.h> // struct timeval
4949
#endif /* _WIN32 */
5050

51+
#include "field_types.h"
5152
#include "my_time_t.h"
5253
#include "mysql_time.h" // struct MYSQL_TIME, shared with client code
5354

54-
enum enum_field_types : int;
55-
5655
extern const unsigned long long int log_10_int[20];
5756
extern const unsigned char days_in_month[];
5857
extern const char my_zero_datetime6[]; /* "0000-00-00 00:00:00.000000" */

Diff for: include/mysql.h.pp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
typedef uint64_t my_ulonglong;
22
typedef int my_socket;
33
#include "field_types.h"
4-
enum enum_field_types
5-
{ MYSQL_TYPE_DECIMAL,
4+
enum enum_field_types {
5+
MYSQL_TYPE_DECIMAL,
66
MYSQL_TYPE_TINY,
77
MYSQL_TYPE_SHORT,
88
MYSQL_TYPE_LONG,
@@ -35,7 +35,8 @@
3535
MYSQL_TYPE_BLOB = 252,
3636
MYSQL_TYPE_VAR_STRING = 253,
3737
MYSQL_TYPE_STRING = 254,
38-
MYSQL_TYPE_GEOMETRY = 255 };
38+
MYSQL_TYPE_GEOMETRY = 255
39+
};
3940
typedef enum enum_field_types enum_field_types;
4041
#include "my_list.h"
4142
typedef struct LIST {

Diff for: include/thr_lock.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct st_lock_list {
136136
};
137137

138138
struct THR_LOCK {
139-
LIST list;
139+
LIST list{nullptr, nullptr, nullptr};
140140
mysql_mutex_t mutex;
141141
struct st_lock_list read_wait;
142142
struct st_lock_list read;

Diff for: libbinlogevents/export/binary_log_funcs.h

-6
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,8 @@
2828
#ifndef BINARY_LOG_FUNCS_INCLUDED
2929
#define BINARY_LOG_FUNCS_INCLUDED
3030

31-
// We use cstdint if this is 2011 standard (or later)
32-
#if __cplusplus > 201100L
33-
#include <cstdint>
34-
enum enum_field_types : int;
35-
#else
3631
#include <stdint.h>
3732
#include "field_types.h" // enum_field_types
38-
#endif
3933

4034
#ifdef __cplusplus
4135
extern "C" {

Diff for: mysys/list.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ void list_free(LIST *root, uint free_data) {
7575
}
7676

7777
LIST *list_cons(void *data, LIST *list) {
78-
LIST *new_charset =
79-
(LIST *)my_malloc(key_memory_LIST, sizeof(LIST), MYF(MY_FAE));
78+
LIST *new_charset = (LIST *)my_malloc(key_memory_LIST, sizeof(LIST),
79+
MYF(MY_FAE | MY_ZEROFILL));
8080
if (!new_charset) return nullptr;
8181
new_charset->data = data;
8282
return list_add(list, new_charset);

Diff for: sql/dd_table_share.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <sys/types.h>
2626

27+
#include "field_types.h"
2728
#include "m_ctype.h"
2829
#include "my_inttypes.h"
2930
#include "my_sys.h" // get_charset
@@ -33,7 +34,6 @@ class Field;
3334
class KEY_PART_INFO;
3435
class THD;
3536
struct TABLE_SHARE;
36-
enum enum_field_types : int;
3737

3838
namespace dd {
3939
class Table;

Diff for: sql/item_create.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <cstddef>
3434

35+
#include "field_types.h"
3536
#include "lex_string.h"
3637
#include "my_inttypes.h" // uint
3738
#include "sql/parse_location.h" // POS
@@ -47,7 +48,6 @@ class THD;
4748
struct Cast_type;
4849
struct CHARSET_INFO;
4950
struct udf_func;
50-
enum enum_field_types : int;
5151
enum class Json_on_response_type : uint16;
5252

5353
/* For type casts */

Diff for: sql/sql_alter.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "lex_string.h"
3333

34+
#include "field_types.h"
3435
#include "my_io.h"
3536
#include "my_sqlcommand.h"
3637
#include "mysql/components/services/bits/psi_bits.h"
@@ -54,8 +55,6 @@ class String;
5455
class THD;
5556
struct TABLE_LIST;
5657

57-
enum enum_field_types : int;
58-
5958
/**
6059
Class representing DROP COLUMN, DROP KEY, DROP FOREIGN KEY, DROP CHECK
6160
CONSTRAINT and DROP CONSTRAINT clauses in ALTER TABLE statement.

Diff for: sql/sql_show.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <stddef.h>
2727
#include <sys/types.h>
2828

29+
#include "field_types.h"
2930
#include "lex_string.h"
3031
#include "my_inttypes.h"
3132
#include "mysql/status_var.h"
@@ -51,7 +52,6 @@ struct TABLE_LIST;
5152
typedef enum enum_mysql_show_type SHOW_TYPE;
5253
enum enum_schema_tables : int;
5354
enum enum_var_type : int;
54-
enum enum_field_types : int;
5555

5656
/** Characters shown for the command in 'show processlist'. */
5757
constexpr const size_t PROCESS_LIST_WIDTH{100};

0 commit comments

Comments
 (0)