diff --git a/CMakeLists.txt b/CMakeLists.txt index 274f22d4861..c96d10d84fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -295,6 +295,14 @@ check_compiler_has_flag( "-Wno-literal-suffix" ) +# This flag is too aggressive and keeps giving false positives. +check_compiler_has_flag( + CXX_FLAGS_STRICT_COMPILATION + "-Wmaybe-uninitialized" + HAS_COMPILER_FLAG_WMAYBE_UNINITIALIZED + "-Wno-maybe-uninitialized" +) + # This removes a lot of warnings from Clang regarding unused -I arguments check_compiler_has_flag( CXX_FLAGS_STRICT_COMPILATION diff --git a/SConstruct b/SConstruct index 4614137adb1..eb11eddc08e 100755 --- a/SConstruct +++ b/SConstruct @@ -474,7 +474,7 @@ for env in [test_env, client_env, env]: env.AppendUnique(CXXFLAGS = ["-fopenmp"], LIBS = ["gomp"]) if env['strict']: - env.AppendUnique(CCFLAGS = Split("-Werror $(-Wno-unused-local-typedefs$)")) + env.AppendUnique(CCFLAGS = Split("-Werror $(-Wno-unused-local-typedefs$) $(-Wno-maybe-uninitialized$)")) env.AppendUnique(CXXFLAGS = Split("-Wold-style-cast")) if env['sanitize']: env.AppendUnique(CCFLAGS = ["-fsanitize=" + env["sanitize"]], LINKFLAGS = ["-fsanitize=" + env["sanitize"]]) diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index aabb2bc8c5a..e11eb57842e 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -332,17 +332,6 @@ bool listbox::update_content_size() return false; } -/* Suppress -Wmaybe-uninitialized warnings. - * @GregoryLundberg reported in IRC that GCC 6.2.1 with SCons gives a warning that the value - * of horizontal_scrollbar_position can be used uninitialized. It's of course not possible - * (boost::optional conversion to bool returns true only if the value is set), but GCC can't - * prove that to itself. - */ -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif - void listbox::place(const point& origin, const point& size) { boost::optional vertical_scrollbar_position, horizontal_scrollbar_position; @@ -375,10 +364,6 @@ void listbox::place(const point& origin, const point& size) } } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif - void listbox::resize_content(const int width_modification, const int height_modification, const int width_modification_pos, diff --git a/src/lexical_cast.hpp b/src/lexical_cast.hpp index c99213dbab3..c0ad866c6b5 100644 --- a/src/lexical_cast.hpp +++ b/src/lexical_cast.hpp @@ -124,16 +124,6 @@ struct bad_lexical_cast : std::exception namespace implementation { -/* Suppress -Wmaybe-uninitialized warnings. - * I (Jyrki) noticed that building with -Og on my system (GCC 7.2.0, Boost 1.61) - * GCC may omit a warning that the value of `fallback` may be used uninitialized. - * It's impossible, but GCC can't prove that to itself. - */ -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif - /** * Base class for the conversion. * @@ -495,10 +485,6 @@ struct lexical_caster< } }; -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif - } // namespace implementation #endif diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 009d8c972b4..13e94a597d5 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -131,13 +131,6 @@ class CVideo; #include "scripting/debug_lua.hpp" #endif -// Suppress uninitialized variables warnings, because of boost::optional constructors in this file which apparently confuses gcc -#if defined(__GNUC__) && !defined(__clang__) // we shouldn't need this for clang, but for gcc and tdm-gcc we probably do -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6 ) // "GCC diagnostic ignored" is apparently not available at version 4.5.2 -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif -#endif - static lg::log_domain log_scripting_lua("scripting/lua"); #define LOG_LUA LOG_STREAM(info, log_scripting_lua) #define WRN_LUA LOG_STREAM(warn, log_scripting_lua) diff --git a/src/xBRZ/xbrz.cpp b/src/xBRZ/xbrz.cpp index e422484f978..13f8d35cff4 100644 --- a/src/xBRZ/xbrz.cpp +++ b/src/xBRZ/xbrz.cpp @@ -43,12 +43,6 @@ #include "utils/functional.hpp" -#if defined(__GNUC__) && !defined(__clang__) && !defined(__WIN32__) // We only want this for gcc, not clang or tdm-gcc -#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 8 ) -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" //Suppress uninitialized variables warnings on GCC <= 4.8.x -#endif -#endif - namespace { template inline