Core: Replace `_NO_DISCARD_` macro with attribute

This commit is contained in:
Thaddeus Crews 2024-04-12 10:02:26 -05:00
parent 30e71782af
commit 55a4836e5b
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
18 changed files with 18 additions and 23 deletions

View File

@ -41,7 +41,7 @@
class Variant; class Variant;
struct _NO_DISCARD_ AABB { struct [[nodiscard]] AABB {
Vector3 position; Vector3 position;
Vector3 size; Vector3 size;

View File

@ -34,7 +34,7 @@
#include "core/math/quaternion.h" #include "core/math/quaternion.h"
#include "core/math/vector3.h" #include "core/math/vector3.h"
struct _NO_DISCARD_ Basis { struct [[nodiscard]] Basis {
Vector3 rows[3] = { Vector3 rows[3] = {
Vector3(1, 0, 0), Vector3(1, 0, 0),
Vector3(0, 1, 0), Vector3(0, 1, 0),

View File

@ -35,7 +35,7 @@
class String; class String;
struct _NO_DISCARD_ Color { struct [[nodiscard]] Color {
union { union {
struct { struct {
float r; float r;

View File

@ -36,7 +36,7 @@
#include "core/math/transform_3d.h" #include "core/math/transform_3d.h"
#include "core/math/vector3.h" #include "core/math/vector3.h"
struct _NO_DISCARD_ Face3 { struct [[nodiscard]] Face3 {
enum Side { enum Side {
SIDE_OVER, SIDE_OVER,
SIDE_UNDER, SIDE_UNDER,

View File

@ -35,7 +35,7 @@
class Variant; class Variant;
struct _NO_DISCARD_ Plane { struct [[nodiscard]] Plane {
Vector3 normal; Vector3 normal;
real_t d = 0; real_t d = 0;

View File

@ -43,7 +43,7 @@ struct Rect2;
struct Transform3D; struct Transform3D;
struct Vector2; struct Vector2;
struct _NO_DISCARD_ Projection { struct [[nodiscard]] Projection {
enum Planes { enum Planes {
PLANE_NEAR, PLANE_NEAR,
PLANE_FAR, PLANE_FAR,

View File

@ -35,7 +35,7 @@
#include "core/math/vector3.h" #include "core/math/vector3.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
struct _NO_DISCARD_ Quaternion { struct [[nodiscard]] Quaternion {
union { union {
struct { struct {
real_t x; real_t x;

View File

@ -38,7 +38,7 @@ class String;
struct Rect2i; struct Rect2i;
struct Transform2D; struct Transform2D;
struct _NO_DISCARD_ Rect2 { struct [[nodiscard]] Rect2 {
Point2 position; Point2 position;
Size2 size; Size2 size;

View File

@ -37,7 +37,7 @@
class String; class String;
struct Rect2; struct Rect2;
struct _NO_DISCARD_ Rect2i { struct [[nodiscard]] Rect2i {
Point2i position; Point2i position;
Size2i size; Size2i size;

View File

@ -38,7 +38,7 @@
class String; class String;
struct _NO_DISCARD_ Transform2D { struct [[nodiscard]] Transform2D {
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of columns array, the basis matrix looks like "on paper": // Warning #1: basis of Transform2D is stored differently from Basis. In terms of columns array, the basis matrix looks like "on paper":
// M = (columns[0][0] columns[1][0]) // M = (columns[0][0] columns[1][0])
// (columns[0][1] columns[1][1]) // (columns[0][1] columns[1][1])

View File

@ -36,7 +36,7 @@
#include "core/math/plane.h" #include "core/math/plane.h"
#include "core/templates/vector.h" #include "core/templates/vector.h"
struct _NO_DISCARD_ Transform3D { struct [[nodiscard]] Transform3D {
Basis basis; Basis basis;
Vector3 origin; Vector3 origin;

View File

@ -37,7 +37,7 @@
class String; class String;
struct Vector2i; struct Vector2i;
struct _NO_DISCARD_ Vector2 { struct [[nodiscard]] Vector2 {
static const int AXIS_COUNT = 2; static const int AXIS_COUNT = 2;
enum Axis { enum Axis {

View File

@ -37,7 +37,7 @@
class String; class String;
struct Vector2; struct Vector2;
struct _NO_DISCARD_ Vector2i { struct [[nodiscard]] Vector2i {
static const int AXIS_COUNT = 2; static const int AXIS_COUNT = 2;
enum Axis { enum Axis {

View File

@ -39,7 +39,7 @@ struct Basis;
struct Vector2; struct Vector2;
struct Vector3i; struct Vector3i;
struct _NO_DISCARD_ Vector3 { struct [[nodiscard]] Vector3 {
static const int AXIS_COUNT = 3; static const int AXIS_COUNT = 3;
enum Axis { enum Axis {

View File

@ -37,7 +37,7 @@
class String; class String;
struct Vector3; struct Vector3;
struct _NO_DISCARD_ Vector3i { struct [[nodiscard]] Vector3i {
static const int AXIS_COUNT = 3; static const int AXIS_COUNT = 3;
enum Axis { enum Axis {

View File

@ -36,7 +36,7 @@
class String; class String;
struct _NO_DISCARD_ Vector4 { struct [[nodiscard]] Vector4 {
static const int AXIS_COUNT = 4; static const int AXIS_COUNT = 4;
enum Axis { enum Axis {

View File

@ -37,7 +37,7 @@
class String; class String;
struct Vector4; struct Vector4;
struct _NO_DISCARD_ Vector4i { struct [[nodiscard]] Vector4i {
static const int AXIS_COUNT = 4; static const int AXIS_COUNT = 4;
enum Axis { enum Axis {

View File

@ -71,12 +71,7 @@
#endif #endif
#endif #endif
// No discard allows the compiler to flag warnings if we don't use the return value of functions / classes // In some cases [[nodiscard]] will get false positives,
#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. // we can prevent the warning in specific cases by preceding the call with a cast.
#ifndef _ALLOW_DISCARD_ #ifndef _ALLOW_DISCARD_
#define _ALLOW_DISCARD_ (void) #define _ALLOW_DISCARD_ (void)