From a12e58b1057f378f8b8f5fd2ba01a82a1a49d9b5 Mon Sep 17 00:00:00 2001 From: mishaparem Date: Mon, 15 Jun 2020 13:45:04 +0300 Subject: [PATCH] fix(Core): C++ 11 rule of 3 compiant constructors (#3023) --- deps/g3dlite/include/G3D/Vector3.h | 55 ++++++++++--------- src/common/Packets/ByteBuffer.h | 19 ++++--- src/common/Packets/WorldPacket.h | 7 ++- src/common/Utilities/Util.h | 5 ++ src/server/game/Entities/Object/Object.h | 14 ++++- src/server/game/Entities/Unit/Unit.h | 8 ++- .../game/Movement/Spline/MoveSplineFlag.h | 6 ++ 7 files changed, 79 insertions(+), 35 deletions(-) diff --git a/deps/g3dlite/include/G3D/Vector3.h b/deps/g3dlite/include/G3D/Vector3.h index b4e684b92..771448d63 100644 --- a/deps/g3dlite/include/G3D/Vector3.h +++ b/deps/g3dlite/include/G3D/Vector3.h @@ -1,8 +1,8 @@ /** @file Vector3.h - + 3D vector class - + @maintainer Morgan McGuire, http://graphics.cs.williams.edu @created 2001-06-02 @@ -36,7 +36,7 @@ class Any; /** Swizzles Vector classes have swizzle operators, e.g. v.xy(), that - allow selection of arbitrary sub-fields. These cannot be used as write + allow selection of arbitrary sub-fields. These cannot be used as write masks. Examples
@@ -74,7 +74,7 @@ public:
 
     /** \param any Must either Vector3(#, #, #) or Vector3 {x = #, y = #, z = #}*/
     Vector3(const Any& any);
-    
+
     /** Converts the Vector3 to an Any. */
     operator Any() const;
 
@@ -116,6 +116,11 @@ public:
 
     // assignment and comparison
     Vector3& __fastcall operator= (const Vector3& rkVector);
+    /* requried as of C++ 11 */
+    #if __cplusplus >= 201103L
+    Vector3(const Vector3&) = default;
+    Vector3(Vector3&&) = default;
+    #endif
     bool operator== (const Vector3& rkVector) const;
     bool operator!= (const Vector3& rkVector) const;
     size_t hashCode() const;
@@ -130,7 +135,7 @@ public:
 
     /** Returns true if this vector has length ~= 1 */
     bool isUnit() const;
-    
+
     // arithmetic operations
     Vector3 __fastcall operator+ (const Vector3& v) const;
     Vector3 __fastcall operator- (const Vector3& v) const;
@@ -156,7 +161,7 @@ public:
 	float length() const;
 
     float magnitude() const;
-    
+
     /**
      The result is a nan vector if the length is almost zero.
      */
@@ -179,7 +184,7 @@ public:
 
      
        V'    N      V
-                 
+
          r   ^   -,
           \  |  /
             \|/
@@ -191,17 +196,17 @@ public:
 
     /**
       See also G3D::Ray::reflect.
-      The length is 1. 
+      The length is 1.
      
        V'    N       V
-                 
+
          r   ^    /
           \  |  /
             \|'-
      
*/ Vector3 reflectionDirection(const Vector3& normal) const; - + /** Returns Vector3::zero() if the length is nearly zero, otherwise @@ -223,7 +228,7 @@ public: where iExit is the index of refraction for the previous material and iEnter is the index of refraction for the new material. Like Vector3::reflectionDirection, - the result has length 1 and is + the result has length 1 and is pointed away from the intersection. Returns Vector3::zero() in the case of total internal refraction. @@ -237,7 +242,7 @@ public: See also G3D::Ray::refract.
               N      V
-                  
+
               ^    /
               |  /
               |'-
@@ -265,9 +270,9 @@ public:
     float squaredLength() const;
 
     float squaredMagnitude () const;
-	
+
     float __fastcall dot(const Vector3& rkVector) const;
-    
+
     float unitize(float tolerance = 1e-06);
 
     /** Cross product.  Note that two cross products in a row
@@ -319,14 +324,14 @@ public:
      Linear interpolation
      */
     inline Vector3 lerp(const Vector3& v, float alpha) const {
-        return (*this) + (v - *this) * alpha; 
+        return (*this) + (v - *this) * alpha;
     }
 
     /** Gram-Schmidt orthonormalization. */
     static void orthonormalize (Vector3 akVector[3]);
 
-    /** \brief Random unit vector, uniformly distributed on the sphere. 
-    
+    /** \brief Random unit vector, uniformly distributed on the sphere.
+
        Distribution rendered by G3D::DirectionHistogram:
        \image html vector3-random.png
       */
@@ -334,8 +339,8 @@ public:
 
     /** \brief Random unit vector, distributed according to \f$\max(\cos \theta,0)\f$.
 
-        That is, so that the probability of \f$\vec{V}\f$ is proportional 
-        to \f$\max(\vec{v} \cdot \vec{n}, 0)\f$.  Useful in photon mapping for 
+        That is, so that the probability of \f$\vec{V}\f$ is proportional
+        to \f$\max(\vec{v} \cdot \vec{n}, 0)\f$.  Useful in photon mapping for
         Lambertian scattering.
 
         Distribution rendered by G3D::DirectionHistogram:
@@ -372,7 +377,7 @@ public:
 
     /** Input W must be initialize to a nonzero vector, output is {U,V,W}
         an orthonormal basis.  A hint is provided about whether or not W
-        is already unit length. 
+        is already unit length.
         @deprecated Use getTangents
     */
     static void generateOrthonormalBasis (Vector3& rkU, Vector3& rkV,
@@ -394,7 +399,7 @@ public:
     static const Vector3& unitZ();
     static const Vector3& inf();
     static const Vector3& nan();
-    
+
     /** Smallest (most negative) representable vector */
     static const Vector3& minFinite();
 
@@ -405,16 +410,16 @@ public:
     /** Creates two orthonormal tangent vectors X and Y such that
         if Z = this, X x Y = Z.*/
     inline void getTangents(Vector3& X, Vector3& Y) const {
-        debugAssertM(G3D::fuzzyEq(length(), 1.0f), 
+        debugAssertM(G3D::fuzzyEq(length(), 1.0f),
                      "makeAxes requires Z to have unit length");
-        
+
         // Choose another vector not perpendicular
         X = (abs(x) < 0.9f) ? Vector3::unitX() : Vector3::unitY();
-        
+
         // Remove the part that is parallel to Z
         X -= *this * this->dot(X);
         X /= X.length();
-    
+
         Y = this->cross(X);
     }
 
diff --git a/src/common/Packets/ByteBuffer.h b/src/common/Packets/ByteBuffer.h
index 86c7d207d..2659afcdc 100644
--- a/src/common/Packets/ByteBuffer.h
+++ b/src/common/Packets/ByteBuffer.h
@@ -72,6 +72,12 @@ class ByteBuffer
             _storage(buf._storage)
         {
         }
+        /* requried as of C++ 11 */
+        #if __cplusplus >= 201103L
+        ByteBuffer(ByteBuffer&&) = default;
+        ByteBuffer& operator=(const ByteBuffer&) = default;
+        ByteBuffer& operator=(ByteBuffer&&) = default;
+        #endif
 
         void clear()
         {
@@ -374,18 +380,18 @@ class ByteBuffer
             return *this;
         }
 
-        uint8 * contents() 
-        { 
+        uint8 * contents()
+        {
             if (_storage.empty())
                 throw ByteBufferException();
-            return &_storage[0]; 
+            return &_storage[0];
         }
 
-        const uint8 *contents() const 
-        { 
+        const uint8 *contents() const
+        {
             if (_storage.empty())
                 throw ByteBufferException();
-            return &_storage[0]; 
+            return &_storage[0];
         }
 
         size_t size() const { return _storage.size(); }
@@ -612,4 +618,3 @@ inline void ByteBuffer::read_skip()
 }
 
 #endif
-
diff --git a/src/common/Packets/WorldPacket.h b/src/common/Packets/WorldPacket.h
index 2c926dfa6..16887ad6e 100644
--- a/src/common/Packets/WorldPacket.h
+++ b/src/common/Packets/WorldPacket.h
@@ -22,6 +22,12 @@ class WorldPacket : public ByteBuffer
         WorldPacket(const WorldPacket &packet)              : ByteBuffer(packet), m_opcode(packet.m_opcode)
         {
         }
+        /* requried as of C++ 11 */
+        #if __cplusplus >= 201103L
+        WorldPacket(WorldPacket&&) = default;
+        WorldPacket& operator=(const WorldPacket&) = default;
+        WorldPacket& operator=(WorldPacket&&) = default;
+        #endif
 
         void Initialize(uint16 opcode, size_t newres=200)
         {
@@ -37,4 +43,3 @@ class WorldPacket : public ByteBuffer
         uint16 m_opcode;
 };
 #endif
-
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h
index ce8a01655..d14a339ac 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -449,6 +449,11 @@ public:
         part[2] = right.part[2];
         return *this;
     }
+    /* requried as of C++ 11 */
+    #if __cplusplus >= 201103L
+    flag96(const flag96&) = default;
+    flag96(flag96&&) = default;
+    #endif
 
     inline flag96 operator&(flag96 const& right) const
     {
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index e5167c03c..43aeb8724 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -376,6 +376,12 @@ struct Position
         : m_positionX(x), m_positionY(y), m_positionZ(z), m_orientation(NormalizeOrientation(o)) { }
 
     Position(Position const& loc) { Relocate(loc); }
+    /* requried as of C++ 11 */
+    #if __cplusplus >= 201103L
+    Position(Position&&) = default;
+    Position& operator=(const Position&) = default;
+    Position& operator=(Position&&) = default;
+    #endif
 
     struct PositionXYStreamer
     {
@@ -639,7 +645,13 @@ class WorldLocation : public Position
     public:
         explicit WorldLocation(uint32 _mapid = MAPID_INVALID, float _x = 0, float _y = 0, float _z = 0, float _o = 0)
             : m_mapId(_mapid) { Relocate(_x, _y, _z, _o); }
-        WorldLocation(const WorldLocation &loc) { WorldRelocate(loc); }
+        WorldLocation(const WorldLocation &loc) : Position () { WorldRelocate(loc); }
+        /* requried as of C++ 11 */
+        #if __cplusplus >= 201103L
+        WorldLocation(WorldLocation&&) = default;
+        WorldLocation& operator=(const WorldLocation&) = default;
+        WorldLocation& operator=(WorldLocation&&) = default;
+        #endif
 
         void WorldRelocate(const WorldLocation &loc)
         {
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index dfae9c1e7..8e54765e4 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -657,7 +657,7 @@ enum NPCFlags
     UNIT_NPC_FLAG_GUILD_BANKER          = 0x00800000,       // cause client to send 997 opcode
     UNIT_NPC_FLAG_SPELLCLICK            = 0x01000000,       // cause client to send 1015 opcode (spell click)
     UNIT_NPC_FLAG_PLAYER_VEHICLE        = 0x02000000,       // players with mounts that have vehicle data should have it set
-    UNIT_NPC_FLAG_MAILBOX               = 0x04000000        // 
+    UNIT_NPC_FLAG_MAILBOX               = 0x04000000        //
 };
 
 enum MovementFlags
@@ -1314,6 +1314,12 @@ public:
         _posOwner.Relocate(c._posOwner);
         _posTarget.Relocate(c._posTarget);
     }
+    /* requried as of C++ 11 */
+    #if __cplusplus >= 201103L
+    MMapTargetData(MMapTargetData&&) = default;
+    MMapTargetData& operator=(const MMapTargetData&) = default;
+    MMapTargetData& operator=(MMapTargetData&&) = default;
+    #endif
     bool PosChanged(const Position& o, const Position& t) const
     {
         return _posOwner.GetExactDistSq(&o) > 0.5f*0.5f || _posTarget.GetExactDistSq(&t) > 0.5f*0.5f;
diff --git a/src/server/game/Movement/Spline/MoveSplineFlag.h b/src/server/game/Movement/Spline/MoveSplineFlag.h
index 6c3ae2801..6740da968 100644
--- a/src/server/game/Movement/Spline/MoveSplineFlag.h
+++ b/src/server/game/Movement/Spline/MoveSplineFlag.h
@@ -68,6 +68,12 @@ namespace Movement
         MoveSplineFlag() { raw() = 0; }
         MoveSplineFlag(uint32 f) { raw() = f; }
         MoveSplineFlag(const MoveSplineFlag& f) { raw() = f.raw(); }
+        /* requried as of C++ 11 */
+        #if __cplusplus >= 201103L
+        MoveSplineFlag(MoveSplineFlag&&) = default;
+        MoveSplineFlag& operator=(const MoveSplineFlag&) = default;
+        MoveSplineFlag& operator=(MoveSplineFlag&&) = default;
+        #endif
 
         // Constant interface