<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61739>61739</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] suggest replacing chained assignments with a sequence of individual assignments
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            enhancement,
            clang-tidy
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          LegalizeAdulthood
      </td>
    </tr>
</table>

<pre>
    Suppose we have code like:
```
// ...
baz = foo = goink = 0;
```
Because the assignments are all daisy-chained together, it makes it difficult for automated refactoring tools to do things like join a variable's declaration with it's first assignment, localize a variable to it's first use, detect redundant assignments and so-on.  Additional analysis could be built into these existing tools, or a simpler clang-tidy replacement can be applied first to enable other tools.

Write a clang-tidy check that splits this chained assignment into a sequence of individual assignments:
```
// ...
goink = 0;
foo = 0;
baz = 0;
```
Disable any such fixit if the variable is of a type that has a custom `operator=` as that might introduce additional side-effects that are not easily detected resulting in broken code should the chained assignment be split into a sequence of individual assignments.

Note that the assignments are emitted starting from the right-most variable in the chain, as the compound assignment `baz = foo = goink = 0;` is equivalent to `baz = (foo = (goink = 0));` due to the [associativity for =](https://en.cppreference.com/w/cpp/language/operator_precedence) being right-to-left, so the sequence of individual assignments should proceed from right-to-left.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVc1u2zgQfhr6MrChUrYTHXxIavi02Mse9rigyZE0DUWqnGFa9-kXpJzawWbRAob1A87w--PIMNMQEA9q96x2x5XJMsZ0-AMH4-kHPrnsZYzRrc7RXQ5_5XmOjPANYTSvCDY6BE8vqNon1RxV86T2zfW3POqT0ifYbDbL89n8ANUeoY-xXodI4aXeNap9_rDFM1qTGUFGhAXthEEYTEIw3oMzxJe1HQ0FdCBxQBkxKf0ZSGAyL8jlxlHfk81eoI8JTJY4GUEHCXtjJSYKA0iMnkEiuAgyU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