﻿# V570\. Variable is assigned to itself\.

The analyzer has detected a potential error: a variable is assigned to itself\.

The example:

```cpp
dst.m_a = src.m_a;
dst.m_b = dst.m_b;
```

The `dst.m_b` variable value remains unchanged because of a typo\. 

The fixed code:

```cpp
dst.m_a = src.m_a;
dst.m_b = src.m_b;
```

The analyzer issues a warning not only for copy assignment but also for move assignment\.

```cpp
dst.m_a = std::move(src.m_a);
```

The analyzer does not issue the warning every time it detects assignment of a variable to itself\. For example, if the variables are enclosed in parentheses\. This method is often used to suppress compiler\-generated warnings\.

The example:

```cpp
int Foo(int foo)
{
  UNREFERENCED_PARAMETER(foo);
  return 1;
}
```

The `UNREFERENCED_PARAMETER` macro is defined in the `WinNT.h` file in the following way:

```cpp
#define UNREFERENCED_PARAMETER(P)          \
  { \
      (P) = (P); \
  }
```

The analyzer recognizes such cases and does not issue the V570 warning for assignment like this:

```cpp
(foo) = (foo);
```

If this approach is not used in the project,  add the following comment to enable the warning:

```cpp
//V_WARN_ON_ARGUMENT_SELF_ASSIGN
```

**Note**\. If the V570 warning is issued for macros that cannot be changed, use macro [suppression](https://pvs-studio.com/en/docs/manual/0017/) via adding special comment in a common project file \(for instance, [`StdAfx.h`](https://pvs-studio.com/en/blog/posts/cpp/0265/)\)\. 

The example:

```cpp
//-V:MY_MACROS:V570
```