Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
langcpp
#include <new>
#include <utility>
 
struct S { /* ... */ }; // Has nonthrowing copy constructor
 
class T {
  int N;
  S *S1;
 
public:
  T(const T &RHS) : N(RHS.N), S1(RHS.S1 ? new S1S(*RHS.S1) : nullptr) {}
  T(T &&RHS) noexcept : N(RHS.N), S1(RHS.S1) noexcept { RHS.S1 = nullptr; }
  ~T() { delete S1; }
 
  // ...
 
  T& operator=(const T &RHS) {
    N = RHS.N;
    delete S1;
    S1 = new S(*RHS.S1);
    return *this;
  }
 
  T& operator==(T &&RHS) noexcept {
    N = RHS.N;
    std::swap(S1, RHS.S1);
    return *this;
  }
};

...

Code Block
bgColor#ccccff
langcpp
#include <new>
#include <utility>
 
struct S { /* ... */ }; // Has nonthrowing copy constructor
 
class T {
  int N;
  S *S1;
 
public:
  T(const T &RHS) : N(RHS.N), S1(RHS.S1 ? new S1S(*RHS.S1) : nullptr) {}
  T(T &&RHS) noexcept : N(RHS.N), S1(RHS.S1) noexcept { RHS.S1 = nullptr; }
  ~T() { delete S1; }

  // ...
 
  T& operator=(const T &RHS) {
    if (this != &RHS) {
      N = RHS.N;
      delete S1;
      try {
        S1 = new S(*RHS.S1);
      } catch (std::bad_alloc &) {
        S1 = nullptr; // For basic exception guarantees
        throw;
      }
    }
    return *this;
  }
 
  T& operator==(T &&RHS) noexcept {
    if (this != &RHS) {
      N = RHS.N;
      std::swap(S1, RHS.S1);
    }
    return *this;
  }
};

...

Code Block
bgColor#ccccff
langcpp
#include <new>
#include <utility>
 
struct S { /* ... */ }; // Has nonthrowing copy constructor
 
class T {
  int N;
  S *S1;
 
public:
  T(const T &RHS) : N(RHS.N), S1(RHS.S1 ? new S1S(*RHS.S1) : nullptr) {}
  T(T &&RHS) noexcept : N(RHS.N), S1(RHS.S1) noexcept { RHS.S1 = nullptr; }
  ~T() { delete S1; }

  // ...
 
  friend void swap(T &LHS, T &RHS) noexcept {
    using std::swap;
    swap(LHS.N, RHS.N);
    swap(LHS.S1, RHS.S1);
  }
 
  T& operator=(T RHS) noexcept {
    swap(*this, RHS);
    return *this;
  }
 
  T& operator==(T &&RHS) noexcept {
    if (this != &RHS) {
      N = RHS.N;
      std::swap(S1, RHS.S1);
    }
    return *this;
  }
};

...

Tool

Version

Checker

Description

 PRQA QA-C++

 
Include Page
PRQA QA-C++_vV
PRQA QA-C++_vV

4072,4073,4075,4076

 

Related Vulnerabilities

...