Contrary to possible developer expectations, a template assignment operator will not suppress the compiler generated _copy assignment operator_. This may lead to incorrect copy semantics for members requiring deep copies.


== Noncompliant Code Example

----
class A
{
public:
// A & operator= ( A const & rhs ) Example 1 - implicitly generated
// {
// i = rhs.i;
// return *this;
// }
  template <typename T>
  T & operator= ( T const & rhs ) // Example 2
  {
    if ( this != &rhs ) {
      delete i;
        i = new int32_t;
      *i = *rhs.i;
    }
    return *this;
  }
private:
  int32_t * i; // Member requires deep copy
};

void f ( A const & a1, A & a2 )
{
  a2 = a1; // Unexpectedly uses Example 1
}
----


== See

* MISRA {cpp}:2008, 14-5-3


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

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