Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A8-4-5: Should have an exception for move constructors
#1
Our static analyzer is complaining about our move constructor because we are not moving the entire "oth" input. Instead, we are doing member-wise move, in compliance with A12-8-1:

Code:
class B
{
public:
  B(B&& oth) : ptr(std::move(oth.ptr)) // Compliant
  {
     oth.ptr = nullptr;
  }
};

Do you agree that A8-4-5 should explicitly clarify that the rule does not apply to move constructors?
Reply
#2
Its a bit difficult to answer your question as B doesn't have any members. We assume it has a member 'sometype *ptr;' but does it have any other members?

If 'ptr' is the only member, then we'd say that the example is compliant with both A8-4-5 and A12-8-1.
Posted by and on behalf of
the MISRA C++ Working Group
Reply
#3
Yes, in the example I took from AUTOSAR, B has only one member of type "std::int32_t* ptr;".

Let's assume it has 2 such members, ptr1 and ptr2, would this be compliant with A8-4-5?

Code:
class B
{
public:
  B(B&& oth) :
    ptr1(std::move(oth.ptr1)),
    ptr2(std::move(oth.ptr2))
  {
     oth.ptr1 = nullptr;
     oth.ptr2 = nullptr;
  }
private:
   std::int32_t* ptr1;
   std::int32_t* ptr2;
};
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)