From f097511b96c7e93f0d62b1c2818208dc11c19851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 27 Mar 2020 16:04:01 +0100 Subject: [PATCH 1/2] Fix another batch of -Wmaybe-uninitialized warnings And simplify code in CSGShape. --- modules/basis_universal/register_types.cpp | 4 ++-- modules/csg/csg_shape.cpp | 12 ++++-------- scene/3d/audio_stream_player_3d.cpp | 3 ++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index bf6bc1debd4..6b74b8bf4aa 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -158,8 +158,8 @@ static Ref basis_universal_unpacker(const Vector &p_buffer) { const uint8_t *ptr = r; int size = p_buffer.size(); - basist::transcoder_texture_format format; - Image::Format imgfmt; + basist::transcoder_texture_format format = basist::transcoder_texture_format::cTFTotalTextureFormats; + Image::Format imgfmt = Image::FORMAT_MAX; switch (*(uint32_t *)(ptr)) { case BASIS_DECOMPRESS_RG: { diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index 848b865efb9..1ed48a573c8 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -742,18 +742,14 @@ CSGBrush *CSGMesh3D::_build_brush() { Vector anormals = arrays[Mesh::ARRAY_NORMAL]; const Vector3 *nr = NULL; - bool nr_used = false; if (anormals.size()) { nr = anormals.ptr(); - nr_used = true; } Vector auvs = arrays[Mesh::ARRAY_TEX_UV]; const Vector2 *uvr = NULL; - bool uvr_used = false; if (auvs.size()) { uvr = auvs.ptr(); - uvr_used = true; } Ref mat; @@ -789,10 +785,10 @@ CSGBrush *CSGMesh3D::_build_brush() { for (int k = 0; k < 3; k++) { int idx = ir[j + k]; vertex[k] = vr[idx]; - if (nr_used) { + if (nr) { normal[k] = nr[idx]; } - if (uvr_used) { + if (uvr) { uv[k] = uvr[idx]; } } @@ -832,10 +828,10 @@ CSGBrush *CSGMesh3D::_build_brush() { for (int k = 0; k < 3; k++) { vertex[k] = vr[j + k]; - if (nr_used) { + if (nr) { normal[k] = nr[j + k]; } - if (uvr_used) { + if (uvr) { uv[k] = uvr[j + k]; } } diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index bddf748be7c..9f5170fa989 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "audio_stream_player_3d.h" + #include "core/engine.h" #include "scene/3d/area_3d.h" #include "scene/3d/camera_3d.h" @@ -96,7 +97,7 @@ static const Vector3 speaker_directions[7] = { }; void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tightness, AudioStreamPlayer3D::Output &output) { - unsigned int speaker_count; // only main speakers (no LFE) + unsigned int speaker_count = 0; // only main speakers (no LFE) switch (AudioServer::get_singleton()->get_speaker_mode()) { case AudioServer::SPEAKER_MODE_STEREO: speaker_count = 2; From 72ea74bcc15e4a53f74e217ece0eea6d7aed04ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 27 Mar 2020 16:04:26 +0100 Subject: [PATCH 2/2] SCons: Treat all warnings as errors After an effort spanning several years, we should now be warning-free on all major compilers, so we can set `-Werror` to ensure that we don't introduce warnings in new code. Disable -Werror=strict-overflow on GCC 7 though, as it seems bogus and was fixed in 8+. --- SConstruct | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 693137f77f8..373fd098af9 100644 --- a/SConstruct +++ b/SConstruct @@ -126,7 +126,7 @@ opts.Add(BoolVariable("xaudio2", "Enable the XAudio2 audio driver", False)) opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False)) opts.Add(BoolVariable("progress", "Show a progress indicator during compilation", True)) opts.Add(EnumVariable("warnings", "Level of compilation warnings", "all", ("extra", "all", "moderate", "no"))) -opts.Add(BoolVariable("werror", "Treat compiler warnings as errors", False)) +opts.Add(BoolVariable("werror", "Treat compiler warnings as errors", True)) opts.Add(BoolVariable("dev", "If yes, alias for verbose=yes warnings=extra werror=yes", False)) opts.Add("extra_suffix", "Custom extra suffix added to the base filename of all generated binary files", "") opts.Add(BoolVariable("vsproj", "Generate a Visual Studio solution", False)) @@ -448,6 +448,8 @@ if selected_platform in platform_list: # FIXME: Temporary workaround after the Vulkan merge, remove once warnings are fixed. if methods.using_gcc(env): env.Append(CXXFLAGS=["-Wno-error=cpp"]) + if cc_version_major == 7: # Bogus warning fixed in 8+. + env.Append(CCFLAGS=["-Wno-error=strict-overflow"]) else: env.Append(CXXFLAGS=["-Wno-error=#warnings"]) else: # always enable those errors