Skip to content

Commit

Permalink
Merge pull request #56972 from lawnjelly/warn_unused
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jan 20, 2022
2 parents 3eb585e + b411a73 commit 9e0973c
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion core/math/aabb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
class Variant;

class AABB {
class _NO_DISCARD_ AABB {
public:
Vector3 position;
Vector3 size;
Expand Down
2 changes: 1 addition & 1 deletion core/math/basis.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "core/math/quaternion.h"
#include "core/math/vector3.h"

class Basis {
class _NO_DISCARD_ Basis {
private:
void _set_diagonal(const Vector3 &p_diag);

Expand Down
2 changes: 1 addition & 1 deletion core/math/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "core/math/math_funcs.h"
#include "core/string/ustring.h"

struct Color {
struct _NO_DISCARD_ Color {
union {
struct {
float r;
Expand Down
2 changes: 1 addition & 1 deletion core/math/face3.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "core/math/transform_3d.h"
#include "core/math/vector3.h"

class Face3 {
class _NO_DISCARD_ Face3 {
public:
enum Side {
SIDE_OVER,
Expand Down
2 changes: 1 addition & 1 deletion core/math/plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class Variant;

class Plane {
class _NO_DISCARD_ Plane {
public:
Vector3 normal;
real_t d = 0;
Expand Down
2 changes: 1 addition & 1 deletion core/math/quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "core/math/vector3.h"
#include "core/string/ustring.h"

class Quaternion {
class _NO_DISCARD_ Quaternion {
public:
union {
struct {
Expand Down
4 changes: 2 additions & 2 deletions core/math/rect2.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

struct Transform2D;

struct Rect2 {
struct _NO_DISCARD_ Rect2 {
Point2 position;
Size2 size;

Expand Down Expand Up @@ -363,7 +363,7 @@ struct Rect2 {
}
};

struct Rect2i {
struct _NO_DISCARD_ Rect2i {
Point2i position;
Size2i size;

Expand Down
2 changes: 1 addition & 1 deletion core/math/transform_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include "core/math/rect2.h" // also includes vector2, math_funcs, and ustring

struct Transform2D {
struct _NO_DISCARD_ Transform2D {
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper":
// M = (elements[0][0] elements[1][0])
// (elements[0][1] elements[1][1])
Expand Down
2 changes: 1 addition & 1 deletion core/math/transform_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "core/math/basis.h"
#include "core/math/plane.h"

class Transform3D {
class _NO_DISCARD_ Transform3D {
public:
Basis basis;
Vector3 origin;
Expand Down
4 changes: 2 additions & 2 deletions core/math/vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

struct Vector2i;

struct Vector2 {
struct _NO_DISCARD_ Vector2 {
static const int AXIS_COUNT = 2;

enum Axis {
Expand Down Expand Up @@ -284,7 +284,7 @@ typedef Vector2 Point2;

/* INTEGER STUFF */

struct Vector2i {
struct _NO_DISCARD_ Vector2i {
enum Axis {
AXIS_X,
AXIS_Y,
Expand Down
2 changes: 1 addition & 1 deletion core/math/vector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "core/string/ustring.h"
class Basis;

struct Vector3 {
struct _NO_DISCARD_ Vector3 {
static const int AXIS_COUNT = 3;

enum Axis {
Expand Down
2 changes: 1 addition & 1 deletion core/math/vector3i.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "core/string/ustring.h"
#include "core/typedefs.h"

struct Vector3i {
struct _NO_DISCARD_ Vector3i {
enum Axis {
AXIS_X,
AXIS_Y,
Expand Down
11 changes: 11 additions & 0 deletions core/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@
#endif
#endif

// No discard allows the compiler to flag warnings if we don't use the return value of functions / classes
#ifndef _NO_DISCARD_
#define _NO_DISCARD_ [[nodiscard]]
#endif

// In some cases _NO_DISCARD_ will get false positives,
// we can prevent the warning in specific cases by preceding the call with a cast.
#ifndef _ALLOW_DISCARD_
#define _ALLOW_DISCARD_ (void)
#endif

// Windows badly defines a lot of stuff we'll never use. Undefine it.
#ifdef _WIN32
#undef min // override standard definition
Expand Down
3 changes: 2 additions & 1 deletion editor/import/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,8 @@ void ResourceImporterScene::_optimize_track_usage(AnimationPlayer *p_player, Ani
if (bone_idx == -1) {
continue;
}
skel->get_bone_pose(bone_idx);
// Note that this is using get_bone_pose to update the bone pose cache.
_ALLOW_DISCARD_ skel->get_bone_pose(bone_idx);
loc = skel->get_bone_pose_position(bone_idx);
rot = skel->get_bone_pose_rotation(bone_idx);
scale = skel->get_bone_pose_scale(bone_idx);
Expand Down
6 changes: 3 additions & 3 deletions platform/osx/display_server_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ - (void)windowDidBecomeKey:(NSNotification *)notification {
CGPoint lMouseWarpPos = { pointOnScreen.x, CGDisplayBounds(CGMainDisplayID()).size.height - pointOnScreen.y };
CGWarpMouseCursorPosition(lMouseWarpPos);
} else {
_get_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]);
_ALLOW_DISCARD_ _get_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]);
Input::get_singleton()->set_mouse_position(wd.mouse_pos);
}

Expand Down Expand Up @@ -1391,7 +1391,7 @@ - (void)scrollWheel:(NSEvent *)event {

double deltaX, deltaY;

_get_mouse_pos(wd, [event locationInWindow]);
_ALLOW_DISCARD_ _get_mouse_pos(wd, [event locationInWindow]);

deltaX = [event scrollingDeltaX];
deltaY = [event scrollingDeltaY];
Expand Down Expand Up @@ -2463,7 +2463,7 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay
[wd.window_object setFrameTopLeftPoint:NSMakePoint(position.x - offset.x, position.y - offset.y)];

_update_window(wd);
_get_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]);
_ALLOW_DISCARD_ _get_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]);
}

void DisplayServerOSX::window_set_max_size(const Size2i p_size, WindowID p_window) {
Expand Down
4 changes: 2 additions & 2 deletions scene/main/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,8 @@ void CanvasItem::set_notify_transform(bool p_enable) {
notify_transform = p_enable;

if (notify_transform && is_inside_tree()) {
//this ensures that invalid globals get resolved, so notifications can be received
get_global_transform();
// This ensures that invalid globals get resolved, so notifications can be received.
_ALLOW_DISCARD_ get_global_transform();
}
}

Expand Down
2 changes: 1 addition & 1 deletion scene/resources/immediate_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ AABB ImmediateMesh::get_aabb() const {
if (i == 0) {
aabb = surfaces[i].aabb;
} else {
aabb.merge(surfaces[i].aabb);
aabb = aabb.merge(surfaces[i].aabb);
}
}
return aabb;
Expand Down
4 changes: 2 additions & 2 deletions servers/rendering/renderer_rd/renderer_scene_render_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ Ref<Image> RendererSceneRenderRD::environment_bake_panorama(RID p_env, bool p_ba
ambient_color_sky_mix = env->ambient_sky_contribution;
const float ambient_energy = env->ambient_light_energy;
ambient_color = env->ambient_light;
ambient_color.to_linear();
ambient_color = ambient_color.to_linear();
ambient_color.r *= ambient_energy;
ambient_color.g *= ambient_energy;
ambient_color.b *= ambient_energy;
Expand All @@ -533,7 +533,7 @@ Ref<Image> RendererSceneRenderRD::environment_bake_panorama(RID p_env, bool p_ba
} else {
const float bg_energy = env->bg_energy;
Color panorama_color = ((environment_background == RS::ENV_BG_CLEAR_COLOR) ? storage->get_default_clear_color() : env->bg_color);
panorama_color.to_linear();
panorama_color = panorama_color.to_linear();
panorama_color.r *= bg_energy;
panorama_color.g *= bg_energy;
panorama_color.b *= bg_energy;
Expand Down

0 comments on commit 9e0973c

Please sign in to comment.