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

    <tr>
        <th>Summary</th>
        <td>
            Clang: Inconsistent AST for special CXXRecordDecl members since D112374
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    https://reviews.llvm.org/D112374 introduced an inconsistency in the AST depending on whether special members are explicitly or implicitly defined.

Consider the code:

```c++
struct A {
#ifdef EXPLICIT
  A(A const&) = default;
  A& operator=(A const&) = default;
#endif
  A& method(A const& x);
};
```

Clang's AST allocates the following:

* One `LValueReferenceType` for `A&`, whose pointee is an `ElaboratedType` naming `A`'s `RecordType`.
* One `LValueReferenceType` for `A const&`, whose pointee is an `ElaboratedType` naming `A`'s `RecordType`.

If `EXPLICIT` is defined, there are no other `LValueReferenceType` nodes for `A`.

However, if `EXPLICIT` is not defined, copy constructor/assignment members are implicitly generated and Clang's AST additionally allocates the following:

* A second `LValueReferenceType` for `A&`, whose pointee is `A`'s `RecordType` with no `ElaboratedType` wrapper.
* A second `LValueReferenceType` for `A const&`, whose pointee is `A`'s `RecordType` with no `ElaboratedType` wrapper.

A similar pattern appears for move operations and `RValueReferenceType`.

The inconsistency appears because `DeclareImplicitCopyConstructor` and friends directly construct the special member signatures but do not add an `ElaboratedType` wrapper as `buildNamedType` does.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VV2P6yYQ_TX4ZXQjB2I7efCDN7lRI1211e2q2lcM45gWgwV4c_PvK0iy-dDettsPyXIcYObMnDnDcO_V3iDWpHgixSbjU-itq1vH5e_K7LPWymPdhzB6whpCt4RuHb4qPPiZ1q_DzLo9odvNfE5ZtQBlgrNyEiiBG1BGWOOVD2jEEZSB0CM0vzyDxBGNVGYP1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