Skip to content

Commit 57d570a

Browse files
committed
WL#11226: Clear all compile warnings
1 parent 811f589 commit 57d570a

21 files changed

+94
-70
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ endif()
335335
add_compile_options(${WERROR})
336336

337337

338-
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 12.0)
338+
if (GCC AND GCC VERSION_GREATER 11)
339339
# Silence a warning produced by a regression in GCC 12.0 and newer
340340
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106199
341341
# Note: The stringop-overflow warnings are shown also during linking phase
@@ -422,7 +422,8 @@ if(MAINTAINER_MODE)
422422
# (and this is the case for MSVC 2015).
423423
# See: http://en.cppreference.com/w/cpp/language/copy_assignment
424424

425-
add_compile_options(/W4 /wd4512 /wd4127)
425+
set_warnings_level(4)
426+
add_compile_options(/wd4512 /wd4127)
426427

427428
elseif(SUNPRO)
428429
else()

cdk/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ IF(MSVC)
150150

151151
# TODO: move to /Wall when code base is ready for this
152152

153-
add_compile_options(/W4)
153+
set_warnings_level(4)
154154

155155
# Note: We disable warnings related to C++11 language because we want this
156156
# to be pure C++ code.

cdk/cmake/DepFindProtobuf.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function(mysqlx_protobuf_generate_cpp SRCS HDRS)
115115
ELSEIF(MSVC)
116116
set_source_files_properties(${srcs}
117117
APPEND_STRING PROPERTY COMPILE_FLAGS
118-
"/W1 /wd4018 /wd4996 /wd4244 /wd4267"
118+
"/wd4018 /wd4996 /wd4244 /wd4267"
119119
)
120120
ENDIF()
121121

cdk/cmake/compiler/MSVC.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ function(set_visibility)
8989
endfunction()
9090

9191

92+
function(set_warnings_level N)
93+
94+
# Note: The /Wn flag must be set only once, otherwise msvc shows warnings
95+
96+
string(REGEX REPLACE "/W[123456789]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
97+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W${N}")
98+
99+
endfunction()
100+
101+
92102
function(set_msvcrt TYPE)
93103

94104
if(TYPE MATCHES "^(STATIC|Static|static)$")

cdk/cmake/gtest.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
# Set up gtest for use by targets in given folder and its sub-folders.
3333
#
3434
MACRO(SETUP_GTEST)
35-
IF (WITH_GTEST)
36-
INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS})
37-
ENDIF (WITH_GTEST)
3835
ENDMACRO(SETUP_GTEST)
3936

4037

@@ -135,6 +132,14 @@ MESSAGE("gtest_main location: ${gtest_main_location}")
135132
add_library(gtest STATIC IMPORTED)
136133
add_library(gtest_main STATIC IMPORTED)
137134

135+
target_include_directories(gtest INTERFACE ${GTEST_INCLUDE_DIRS})
136+
137+
# See: https://stackoverflow.com/questions/42847103/stdtr1-with-visual-studio-2017
138+
139+
target_compile_definitions(gtest INTERFACE
140+
-DGTEST_LANG_CXX11=1
141+
)
142+
138143
set_target_properties(gtest PROPERTIES
139144
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
140145
IMPORTED_LOCATION "${gtest_location}"

cdk/cmake/testing.cmake

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ IF(WITH_TESTS)
144144
set_global(test_tests ${test_tests})
145145

146146
add_library(${TEST} OBJECT ${ARGN})
147+
target_link_libraries(${TEST} gtest)
147148
set_target_properties(${TEST} PROPERTIES FOLDER "Tests")
148149

149150
target_include_directories(${TEST} PRIVATE ${test_includes})
@@ -153,21 +154,18 @@ IF(WITH_TESTS)
153154
if (MSVC)
154155

155156
target_compile_definitions(${TEST} PRIVATE
157+
-D_CRT_SECURE_NO_WARNINGS
156158
-D_SCL_SECURE_NO_WARNINGS
157-
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
158159
)
159160

160161
target_compile_options(${TEST} PRIVATE
161-
/W3
162162
/wd4244
163163
/wd4267
164164
/wd4701
165165
/wd4018
166166
/wd4456 # declaration of hides previous local declaration
167167
)
168168

169-
target_compile_options(${TEST} PUBLIC /std:c++14)
170-
171169
if(STATIC_TESTS_MSVCRT)
172170
target_compile_options(${TEST} PRIVATE
173171
$<$<CONFIG:Debug>:/MTd>
@@ -295,10 +293,7 @@ IF(WITH_TESTS)
295293

296294
if (MSVC)
297295

298-
target_compile_definitions(${target_run_unit_tests} PRIVATE
299-
-D_SCL_SECURE_NO_WARNINGS
300-
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
301-
)
296+
set_warnings_level(3)
302297

303298
target_compile_options(${target_run_unit_tests} PRIVATE
304299
/wd4244

cdk/extra/protobuf/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,18 @@ endif()
9494

9595
set_visibility(hidden)
9696

97-
if(NOT TOOLSET_MSVC AND NOT APPLE)
98-
add_compile_options(-Wno-stringop-overflow -Wno-stringop-overread)
97+
if(GCC AND GCC VERSION_GREATER 11)
98+
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106199
99+
add_compile_options(-Wno-stringop-overflow)
100+
add_compile_options(-Wno-stringop-overread)
101+
endif()
102+
103+
if(NOT MSVC OR CLANG)
104+
add_compile_options(-Wno-unused-const-variable)
105+
endif()
106+
107+
if(WIN32)
108+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS)
99109
endif()
100110

101111
if(APPLE)

cdk/extra/zlib/CMakeLists.txt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,33 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
77
set(VERSION "1.3.1")
88

99
project(zlib VERSION ${VERSION} LANGUAGES C)
10+
include(../setup.cmake)
11+
include(platform)
12+
13+
enable_pic()
1014

11-
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON)
1215
if(WERROR)
1316
add_compile_options(${WERROR})
1417
endif()
1518

19+
if(WIN32)
20+
21+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS)
22+
23+
# warning triggered by one of the sources:
24+
# The POSIX name for this item is deprecated. Instead, use the ISO C and C++
25+
# conformant name: _open. See online help for details.
26+
27+
if(CLANG)
28+
add_compile_options(-Wno-deprecated-declarations)
29+
else()
30+
add_compile_options(/wd4996)
31+
endif()
32+
33+
endif()
34+
35+
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" OFF)
36+
1637
IF(DISABLE_THESE_LINES)
1738
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
1839
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
@@ -151,8 +172,6 @@ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
151172
string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
152173
"\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
153174

154-
add_compile_options(-fPIC)
155-
156175
add_library(zlib STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
157176

158177
target_include_directories(zlib PUBLIC

cdk/extra/zstd/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ if(WERROR)
1919
add_compile_options(${WERROR})
2020
endif()
2121

22+
if(WIN32 AND CLANG)
23+
# This warning shows only when building with clang on Win (clang 18):
24+
# lib\compress\huf_compress.c(519,16): error : unused function 'HUF_isSorted'
25+
add_compile_options(-Wno-unused-function)
26+
endif()
27+
2228

2329
SET(ZSTD_LIB_DIR
2430
"${PROJECT_SOURCE_DIR}/lib")

cdk/mysqlx/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN -DNOGDI)
3131
ADD_DEFINITIONS(-DNOMINMAX)
3232
ADD_DEFINITIONS(-DSIZEOF_LONG=${SIZEOF_LONG} -DSIZEOF_LONG_LONG=${SIZEOF_LONG_LONG})
3333

34-
# TODO: Fix compile warnings in auth_mysql41.cc
35-
36-
if(MSVC)
37-
set_property(SOURCE auth_hash.cc
38-
PROPERTY COMPILE_FLAGS "/W3"
39-
)
40-
endif()
41-
4234
file(GLOB HEADERS *.h)
4335

4436
ADD_LIBRARY(cdk_mysqlx STATIC

common/tests/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ set_property(
3636
PROPERTY COMPILE_DEFINITIONS ""
3737
)
3838

39-
if(WIN32)
40-
add_definitions(
41-
-D_CRT_SECURE_NO_WARNINGS
42-
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
43-
)
44-
45-
endif()
46-
4739
#Add cdk includes because we are using their source tests
4840
add_test_includes(${PROJECT_SOURCE_DIR}/cdk/include)
4941
add_test_includes(${PROJECT_SOURCE_DIR}/cdk/extra/rapidjson/include)

devapi/tests/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ set_property(
3838
PROPERTY COMPILE_DEFINITIONS ""
3939
)
4040

41-
if(WIN32)
42-
add_definitions(
43-
-D_CRT_SECURE_NO_WARNINGS
44-
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
45-
)
46-
47-
endif()
4841

4942
#
5043
# If linking with connector statically, define macro that indicates this

include/mysqlx/common_constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#ifndef MYSQL_COMMON_CONSTANTS_H
3232
#define MYSQL_COMMON_CONSTANTS_H
3333

34-
#include "version_info.h"
34+
#include <version_info.h>
3535

3636
#define DEFAULT_MYSQL_PORT 3306
3737
#define DEFAULT_MYSQLX_PORT 33060

include/mysqlx/devapi/document.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ DLL_WARNINGS_POP
172172
virtual Iterator begin();
173173
virtual Iterator end();
174174

175+
virtual ~DbDoc() {}
176+
175177
friend Impl;
176178
friend DocResult;
177179
friend Value;
@@ -360,6 +362,7 @@ class Value
360362
CATCH_AND_WRAP
361363
}
362364

365+
virtual ~Value() {}
363366

364367
public:
365368

include/mysqlx/devapi/result.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ class Column
484484

485485
public:
486486

487+
virtual ~Column()
488+
{}
489+
487490
friend RowResult;
488491
struct INTERNAL Access;
489492
friend Access;

jdbc/cppconn/callback.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class WebAuthn_Callback
133133
ActionRequested(msg);
134134
}
135135

136+
virtual ~WebAuthn_Callback() {}
137+
136138
};
137139

138140

@@ -188,6 +190,8 @@ class Fido_Callback
188190
FidoActionRequested(msg);
189191
}
190192

193+
virtual ~Fido_Callback() {}
194+
191195
friend class mysql::MySQL_Connection;
192196
friend class mysql::MySQL_Driver;
193197
};

jdbc/extra/otel/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ if(NOT (WIN32 OR APPLE OR CMAKE_SYSTEM_NAME MATCHES "SunOS"))
1919
if(WIN32)
2020
# Note: warning C4996 is triggered by OTel headers (as of version 1.10.0)
2121
target_compile_definitions(otel_api INTERFACE _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING)
22+
23+
else()
24+
25+
# Note: warning triggered by OTel headers reported by clang 18:
26+
# builtin __has_trivial_copy is deprecated; use __is_trivially_copyable instead
27+
28+
target_compile_options(otel_api INTERFACE -Wno-deprecated-builtins)
29+
2230
endif()
2331

2432
endif()

testing/CMakeLists.txt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,13 @@ endif()
4949
add_library(test_harness STATIC test_harness.cc)
5050
set_target_properties(test_harness PROPERTIES FOLDER "Tests")
5151

52+
target_link_libraries(test_harness PUBLIC gtest)
53+
5254
add_test_libraries(test_harness connector)
5355
add_test_includes(${CMAKE_CURRENT_SOURCE_DIR})
5456

5557

56-
if(MSVC)
57-
58-
set(TEST_COMPILE_FLAGS
59-
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
60-
-D_CRT_SECURE_NO_WARNINGS
61-
-D_SCL_SECURE_NO_WARNINGS
62-
)
63-
64-
target_compile_definitions(test_harness PUBLIC
65-
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
66-
)
67-
68-
target_compile_options(test_harness PUBLIC /std:c++14)
69-
70-
else()
58+
if(NOT MSVC)
7159

7260
set(TEST_COMPILE_FLAGS
7361
-Wno-sign-compare

xapi/tests/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ set_property(
3636
PROPERTY COMPILE_DEFINITIONS ""
3737
)
3838

39-
IF(WIN32)
40-
add_definitions(
41-
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
42-
)
43-
ENDIF()
44-
4539
if(BUILD_STATIC)
4640
add_definitions(-DSTATIC_CONCPP)
4741
endif()

xapi/tests/xapi-t.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ void check_compress(mysqlx_session_t *sess)
6767

6868
buf_len = 65536;
6969
memset(buf, 0, buf_len);
70-
EXPECT_NE(nullptr, row = mysqlx_row_fetch_one(res));
70+
row = mysqlx_row_fetch_one(res);
71+
EXPECT_FALSE(nullptr == row);
7172
EXPECT_EQ(RESULT_OK, mysqlx_get_bytes(row, 0, 0, buf, &buf_len));
7273
test_row("Test ", buf);
7374

7475
buf_len = 65536;
7576
memset(buf, 0, buf_len);
76-
EXPECT_NE(nullptr, row = mysqlx_row_fetch_one(res));
77+
row = mysqlx_row_fetch_one(res);
78+
EXPECT_FALSE(nullptr == row);
7779
EXPECT_EQ(RESULT_OK, mysqlx_get_bytes(row, 0, 0, buf, &buf_len));
7880
test_row("0123 ", buf);
7981

@@ -2552,7 +2554,6 @@ TEST_F(xapi, dns_srv)
25522554
//Specifying a port number with DNS SRV lookup is not allowed.
25532555

25542556
{
2555-
25562557
EXPECT_EQ(nullptr, mysqlx_get_client_from_url("mysqlx+srv://root@_mysqlx._tcp.localhost:33060",
25572558
nullptr, &error));
25582559
std::cout << "Expected Error: " << mysqlx_error_message(error) << std::endl;
@@ -2949,7 +2950,7 @@ TEST_F(xapi, tls_ver_ciphers)
29492950
error = NULL;
29502951
sess = mysqlx_get_session_from_options(opt, &error);
29512952
mysqlx_free(error);
2952-
EXPECT_NE(NULL, sess);
2953+
EXPECT_FALSE(NULL == sess);
29532954
mysqlx_session_close(sess);
29542955

29552956

xapi/tests/xapi_crud-t.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ TEST_F(xapi, basic)
754754
const char *col_schema = mysqlx_column_get_schema(res, i);
755755
const char *col_cat = mysqlx_column_get_catalog(res, i);
756756

757-
EXPECT_NE(nullptr, col_cat);
757+
EXPECT_FALSE(nullptr == col_cat);
758758

759759
printf("\n Column # %d", i + 1);
760760
printf("\n * name: %s, orig name: %s, table: %s, orig table: %s, schema: %s, catalog: %s",

0 commit comments

Comments
 (0)