Skip to content

Commit 2de0b29

Browse files
author
Tor Didriksen
committed
Bug #32757201 FIX GCC 11 BUILD WARNINGS IN 5.7
Buiding with gcc11, we get misc new warnings. This patch fixes warnings for Debug builds: [-Werror=free-nonheap-object] for code generated by Bison. [-Werror=nonnull] [-Werror=maybe-uninitialized] [-Werror=misleading-indentation] The [-Werror=nonnull] warnings were issued whenever we call a member function directly on the result of a dynamic_cast. Fixed by using pointer_cast and down_cast instead. Change-Id: Ia38715d9bed7f358a084db7d9485b04302d737a6
1 parent 690a84a commit 2de0b29

File tree

7 files changed

+42
-7
lines changed

7 files changed

+42
-7
lines changed

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ IF(CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR STREQUAL "Xcode")
168168
SET(BUILD_IS_SINGLE_CONFIG FALSE)
169169
ENDIF()
170170

171+
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
172+
SET(MY_COMPILER_IS_CLANG 1)
173+
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
174+
SET(MY_COMPILER_IS_GNU 1)
175+
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "SunPro")
176+
SET(MY_COMPILER_IS_SUNPRO 1)
177+
ENDIF()
178+
179+
IF(MY_COMPILER_IS_CLANG OR MY_COMPILER_IS_GNU)
180+
SET(MY_COMPILER_IS_GNU_OR_CLANG 1)
181+
ENDIF()
182+
171183
# Maintainer mode is default on only for debug builds using GCC/G++
172184
IF(CMAKE_BUILD_TYPE MATCHES "Debug" OR WITH_DEBUG)
173185
IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)

libmysqld/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ IF(HAVE_MAYBE_UNINITIALIZED)
197197
COMPILE_FLAGS "-Wno-maybe-uninitialized")
198198
ENDIF()
199199

200+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98753
201+
IF(MY_COMPILER_IS_GNU AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
202+
ADD_COMPILE_FLAGS(
203+
${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
204+
${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
205+
COMPILE_FLAGS "-Wno-free-nonheap-object")
206+
ENDIF()
207+
200208
# Handle out-of-source build from source package with possibly broken
201209
# bison. Copy bison output to from source to build directory, if not already
202210
# there

sql/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ IF(HAVE_MAYBE_UNINITIALIZED)
388388
COMPILE_FLAGS "-Wno-maybe-uninitialized")
389389
ENDIF()
390390

391+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98753
392+
IF(MY_COMPILER_IS_GNU AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
393+
ADD_COMPILE_FLAGS(
394+
${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
395+
${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
396+
COMPILE_FLAGS "-Wno-free-nonheap-object")
397+
ENDIF()
398+
391399
MY_CHECK_CXX_COMPILER_FLAG("-fno-builtin-memcmp" HAVE_NO_BUILTIN_MEMCMP)
392400
# See comments in filesort_compare-t.cc about __builtin_memcmp
393401
IF(HAVE_NO_BUILTIN_MEMCMP)

sql/sys_vars.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1275,8 +1275,8 @@ static bool check_storage_engine(sys_var *self, THD *thd, set_var *var)
12751275
{
12761276
// Use the default value defined by sys_var.
12771277
lex_string_set(&se_name,
1278-
reinterpret_cast<const char*>(
1279-
dynamic_cast<Sys_var_plugin*>(self)->global_value_ptr(thd, NULL)));
1278+
pointer_cast<const char*>(
1279+
down_cast<Sys_var_plugin*>(self)->global_value_ptr(thd, NULL)));
12801280
}
12811281

12821282
plugin_ref plugin;

storage/innobase/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
186186
ENDIF()
187187
ENDIF()
188188

189+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98753
190+
IF(MY_COMPILER_IS_GNU AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
191+
ADD_COMPILE_FLAGS(
192+
pars/pars0grm.cc
193+
COMPILE_FLAGS "-Wno-free-nonheap-object")
194+
ENDIF()
195+
189196
MY_CHECK_CXX_COMPILER_FLAG("-Wcast-function-type" HAVE_CAST_FUNCTION_TYPE)
190197
IF(HAVE_CAST_FUNCTION_TYPE)
191198
ADD_COMPILE_FLAGS(fts/fts0pars.cc

testclients/mysql_client_test.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -18145,9 +18145,9 @@ static void test_bug40365(void)
1814518145
if (!opt_silent)
1814618146
fprintf(stdout, "\ntime[%d]: %02d-%02d-%02d ",
1814718147
i, tm[i].year, tm[i].month, tm[i].day);
18148-
DIE_UNLESS(tm[i].year == 0);
18149-
DIE_UNLESS(tm[i].month == 0);
18150-
DIE_UNLESS(tm[i].day == 0);
18148+
DIE_UNLESS(tm[i].year == 0);
18149+
DIE_UNLESS(tm[i].month == 0);
18150+
DIE_UNLESS(tm[i].day == 0);
1815118151
}
1815218152
mysql_stmt_close(stmt);
1815318153
rc= mysql_commit(mysql);

unittest/gunit/strings_utf8-t.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ TEST_F(StringsUTF8Test, MyWellFormedLenUtf8)
185185

186186
TEST_F(StringsUTF8Test, MyIsmbcharUtf8)
187187
{
188-
char utf8_src[8];
188+
char utf8_src[8] = { 0 };
189189

190190
/* valid utf8 charaters, testing for boundry values */
191191
utf8_src[0]= '\x00';
@@ -362,7 +362,7 @@ TEST_F(StringsUTF8mb4Test, MyWellFormedLenUtf8mb4)
362362

363363
TEST_F(StringsUTF8mb4Test, MyIsmbcharUtf8mb4)
364364
{
365-
char utf8_src[8];
365+
char utf8_src[8] = { 0 };
366366

367367
/* valid utf8mb4 charaters, testing for boundry values */
368368
utf8_src[0]= '\x00';

0 commit comments

Comments
 (0)