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

    <tr>
        <th>Summary</th>
        <td>
            AST Matcher binds wrong TypedefDecl object
        </td>
    </tr>

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

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

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

<pre>
    I  have this code:

`struct AnInterface {};`

`typedef AnInterface ABase1;`
`class AClass1 : public ABase1 {};`

`typedef AnInterface ABase2;`
`class AClass2 : public ABase2 {};`

And this ASTMatcher:

`cxxRecordDecl(`
`  isDerivedFrom(`
` decl().bind("typedef")`
`  )`
`).bind("record")`

The second match wrongly binds `AClass2` and **`ABase1`**.
The same behavior occurs with
`using ABase1=AnInterface`

Output of clang-query:

> clang-query> m cxxRecordDecl( isDerivedFrom( decl().bind("typedef") ) ).bind("record")

> Match #1:
> [... works as expected]

> Match #2:

> typedef_problem.cpp:9:1: note: "record" binds here
>     9 | class AClass2 : public ABase2 {};
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> typedef_problem.cpp:9:1: note: "root" binds here
>     9 | class AClass2 : public ABase2 {};
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> typedef_problem.cpp:5:1: note: "typedef" binds here
>     5 | typedef AnInterface **ABase1**;
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~
> 2 matches.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVE2PozgQ_TXmUmoEJoRw4ECajtSH1UqbaK8rY1eCdwGztkk6l_ntI4MnH9PpUfdtCJETu96r57JfMWPkoUcsSLomaRWw0TZKF1uLR-y3vOmksGX1d1ArcS5eARp2RLCNNMCVQJKUJJreZWSsHrmFsn_tLeo94wgkW5OsIsmaLKNLnD0PKHB_F1iumcH4GriMeMuMgfLZDTGQpIRhrFvJfegXqelH1PQdNX1AXfZi3nO53f3BLG9Q3-6cv739hVxpUSFvCV1dMgFIU6GWRxQbrbq7JeFjaR7WshfTT-o3QCglNL-huf13j9BT4jtAVO4aBINc9QI6JxdOWvWH9gwOZ4AsI797R856AYSW7l1G_iBcFjcT_iBjHUKNDTtKpUFxPmoDJ2mbWdJoZH-4HGJ1U_6LpD9HO4wW1B54y_rD0_8j6vO1iMnL_fwLdPBzWd8V8xM1BP_9qGJzaj9MRwuEJrEX5pbSdRiGcFL6PwPMAL4NyC0KklYfgOkNeB68on8GreoWu5APA0nKnCSlSwS9ss5IcKvNn1SDGj2Je3Ig2TN8_v5ekTAhSfry7dfP1xUrZX9XvekDvdfb8VhyOiV-1EhmR_hLPvvli5J9MJ1Nica5KxBFIvIkZwEWcZbk8YrSNA6agsU0W-15lPI8q1cxjxmPF0ma05wtooTGgSxoRNOIxpH7pHGYpoLlvOYYZavVPtuTRYQdk23YtscuVPoQSGNGLGK6XOSroGU1tmbq-5T2eIJp1fkirQJdONBTPR4MWUStNNZcaay0LRbldge-GfpSTl0GdnPtnGlB1f8it8Go26KxdjDOGnRD6OYgbTPWIXc-3jhiPzwNWjkIoZtJjiF04_UeC_o9AAD___h6AW8">