If a compiler implementation detects that a call to a copy constructor is redundant, then it is permitted to omit that call, even if the copy constructor has a side effect other than the construction of a copy of the object. This is called "copy elision".

It is therefore important to ensure that a copy constructor does not modify the program state, since the number of such modifications may be indeterminate.


== Noncompliant Code Example

----
class A
{
public:
  A ( A const & rhs )
  : m_i ( rhs.m_i )
  {
    ++m_static; // Non-compliant, might not be executed
  }
private:
  int32_t m_i;
  static int32_t m_static;
};
----


== See

* MISRA {cpp}:2008, 12-8-1
* https://wiki.sei.cmu.edu/confluence/x/gXs-BQ[CERT, OOP58-CPP.] - Copy operations must not mutate the source object


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
