Skip to content

Commit

Permalink
Enable shadow warnings and fix raised errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed May 11, 2023
1 parent fd4a06c commit 71ee65d
Show file tree
Hide file tree
Showing 27 changed files with 785 additions and 767 deletions.
6 changes: 4 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,8 @@ if selected_platform in platform_list:
if env["warnings"] == "extra":
env.Append(CCFLAGS=["/W4"])
elif env["warnings"] == "all":
env.Append(CCFLAGS=["/W3"])
# C4458 is like -Wshadow. Part of /W4 but let's apply it for the default /W3 too.
env.Append(CCFLAGS=["/W3", "/w4458"])
elif env["warnings"] == "moderate":
env.Append(CCFLAGS=["/W2"])
# Disable warnings which we don't plan to fix.
Expand Down Expand Up @@ -727,7 +728,7 @@ if selected_platform in platform_list:
common_warnings = []

if methods.using_gcc(env):
common_warnings += ["-Wshadow-local", "-Wno-misleading-indentation"]
common_warnings += ["-Wshadow", "-Wno-misleading-indentation"]
if cc_version_major == 7: # Bogus warning fixed in 8+.
common_warnings += ["-Wno-strict-overflow"]
if cc_version_major < 11:
Expand All @@ -737,6 +738,7 @@ if selected_platform in platform_list:
if cc_version_major >= 12: # False positives in our error macros, see GH-58747.
common_warnings += ["-Wno-return-type"]
elif methods.using_clang(env) or methods.using_emcc(env):
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local"]
# We often implement `operator<` for structs of pointers as a requirement
# for putting them in `Set` or `Map`. We don't mind about unreliable ordering.
common_warnings += ["-Wno-ordered-compare-function-pointers"]
Expand Down
20 changes: 10 additions & 10 deletions core/math/convex_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,9 @@ class ConvexHullInternal {
}
};

enum Orientation { NONE,
CLOCKWISE,
COUNTER_CLOCKWISE };
enum Orientation { ORIENTATION_NONE,
ORIENTATION_CLOCKWISE,
ORIENTATION_COUNTER_CLOCKWISE };

Vector3 scaling;
Vector3 center;
Expand Down Expand Up @@ -1140,13 +1140,13 @@ ConvexHullInternal::Orientation ConvexHullInternal::get_orientation(const Edge *
CHULL_ASSERT(!m.is_zero());
int64_t dot = n.dot(m);
CHULL_ASSERT(dot != 0);
return (dot > 0) ? COUNTER_CLOCKWISE : CLOCKWISE;
return (dot > 0) ? ORIENTATION_COUNTER_CLOCKWISE : ORIENTATION_CLOCKWISE;
}
return COUNTER_CLOCKWISE;
return ORIENTATION_COUNTER_CLOCKWISE;
} else if (p_prev->prev == p_next) {
return CLOCKWISE;
return ORIENTATION_CLOCKWISE;
} else {
return NONE;
return ORIENTATION_NONE;
}
}

Expand Down Expand Up @@ -1176,7 +1176,7 @@ ConvexHullInternal::Edge *ConvexHullInternal::find_max_angle(bool p_ccw, const V
} else if ((cmp = cot.compare(p_min_cot)) < 0) {
p_min_cot = cot;
min_edge = e;
} else if ((cmp == 0) && (p_ccw == (get_orientation(min_edge, e, p_s, t) == COUNTER_CLOCKWISE))) {
} else if ((cmp == 0) && (p_ccw == (get_orientation(min_edge, e, p_s, t) == ORIENTATION_COUNTER_CLOCKWISE))) {
min_edge = e;
}
}
Expand Down Expand Up @@ -1375,7 +1375,7 @@ void ConvexHullInternal::merge(IntermediateHull &p_h0, IntermediateHull &p_h1) {
int64_t dot = (*e->target - *c0).dot(normal);
CHULL_ASSERT(dot <= 0);
if ((dot == 0) && ((*e->target - *c0).dot(t) > 0)) {
if (!start0 || (get_orientation(start0, e, s, Point32(0, 0, -1)) == CLOCKWISE)) {
if (!start0 || (get_orientation(start0, e, s, Point32(0, 0, -1)) == ORIENTATION_CLOCKWISE)) {
start0 = e;
}
}
Expand All @@ -1390,7 +1390,7 @@ void ConvexHullInternal::merge(IntermediateHull &p_h0, IntermediateHull &p_h1) {
int64_t dot = (*e->target - *c1).dot(normal);
CHULL_ASSERT(dot <= 0);
if ((dot == 0) && ((*e->target - *c1).dot(t) > 0)) {
if (!start1 || (get_orientation(start1, e, s, Point32(0, 0, -1)) == COUNTER_CLOCKWISE)) {
if (!start1 || (get_orientation(start1, e, s, Point32(0, 0, -1)) == ORIENTATION_COUNTER_CLOCKWISE)) {
start1 = e;
}
}
Expand Down
16 changes: 8 additions & 8 deletions core/math/static_raycaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class StaticRaycaster : public RefCounted {

/*! Constructs a ray from origin, direction, and ray segment. Near
* has to be smaller than far. */
_FORCE_INLINE_ Ray(const Vector3 &org,
const Vector3 &dir,
float tnear = 0.0f,
float tfar = INFINITY) :
org(org),
tnear(tnear),
dir(dir),
_FORCE_INLINE_ Ray(const Vector3 &p_org,
const Vector3 &p_dir,
float p_tnear = 0.0f,
float p_tfar = INFINITY) :
org(p_org),
tnear(p_tnear),
dir(p_dir),
time(0.0f),
tfar(tfar),
tfar(p_tfar),
mask(-1),
u(0.0),
v(0.0),
Expand Down
8 changes: 4 additions & 4 deletions core/os/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ String Time::get_time_string_from_system(bool p_utc) const {

Dictionary Time::get_time_zone_from_system() const {
OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
Dictionary timezone;
timezone["bias"] = info.bias;
timezone["name"] = info.name;
return timezone;
Dictionary ret_timezone;
ret_timezone["bias"] = info.bias;
ret_timezone["name"] = info.name;
return ret_timezone;
}

double Time::get_unix_time_from_system() const {
Expand Down
6 changes: 5 additions & 1 deletion drivers/gl_context/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ if env["platform"] in ["haiku", "macos", "windows", "linuxbsd"]:
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

env.Prepend(CPPPATH=[thirdparty_dir])
# Treat glad headers as system headers to avoid raising warnings. Not supported on MSVC.
if not env.msvc:
env.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path])
else:
env.Prepend(CPPPATH=[thirdparty_dir])

env.Append(CPPDEFINES=["GLAD_ENABLED"])
env.Append(CPPDEFINES=["GLES_OVER_GL"])
Expand Down
4 changes: 2 additions & 2 deletions drivers/pulseaudio/audio_driver_pulseaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ Error AudioDriverPulseAudio::init_output_device() {
break;
}

int latency = GLOBAL_GET("audio/driver/output_latency");
buffer_frames = closest_power_of_2(latency * mix_rate / 1000);
int tmp_latency = GLOBAL_GET("audio/driver/output_latency");
buffer_frames = closest_power_of_2(tmp_latency * mix_rate / 1000);
pa_buffer_size = buffer_frames * pa_map.channels;

print_verbose("PulseAudio: detected " + itos(pa_map.channels) + " output channels");
Expand Down
12 changes: 6 additions & 6 deletions drivers/unix/file_access_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ bool FileAccessUnix::file_exists(const String &p_path) {

uint64_t FileAccessUnix::_get_modified_time(const String &p_file) {
String file = fix_path(p_file);
struct stat flags = {};
int err = stat(file.utf8().get_data(), &flags);
struct stat status = {};
int err = stat(file.utf8().get_data(), &status);

if (!err) {
return flags.st_mtime;
return status.st_mtime;
} else {
print_verbose("Failed to get modified time for: " + p_file + "");
return 0;
Expand All @@ -314,11 +314,11 @@ uint64_t FileAccessUnix::_get_modified_time(const String &p_file) {

uint32_t FileAccessUnix::_get_unix_permissions(const String &p_file) {
String file = fix_path(p_file);
struct stat flags = {};
int err = stat(file.utf8().get_data(), &flags);
struct stat status = {};
int err = stat(file.utf8().get_data(), &status);

if (!err) {
return flags.st_mode & 0x7FF; //only permissions
return status.st_mode & 0x7FF; //only permissions
} else {
ERR_FAIL_V_MSG(0, "Failed to get unix permissions for: " + p_file + ".");
}
Expand Down
Loading

0 comments on commit 71ee65d

Please sign in to comment.