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

    <tr>
        <th>Summary</th>
        <td>
            [[Clang]] Unexpected source location in method chaining
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          16bit-ykiko
      </td>
    </tr>
</table>

<pre>
    ![Image](https://github.com/user-attachments/assets/8f6abbf2-f9d7-4233-8676-09cb1e0114ff)
https://godbolt.org/z/d3WeT6d7W

As you can see, clang gives same source location for all function in method chaining. But GCC and MSVC gives different and actually better results.

After checking AST
```
-FunctionDecl <line:11:1, line:17:1> line:11:5 main 'int ()'
  `-CompoundStmt <col:12, line:17:1>
 `-ExprWithCleanups <line:12:5, line:16:13> 'X' lvalue
 `-CXXMemberCallExpr <line:12:5, line:16:13> 'X' lvalue
        |-MemberExpr <line:12:5, line:16:9> '<bound member function type>' .foo 0xe8a7ac0
 | `-CXXMemberCallExpr <line:12:5, line:15:13> 'X' lvalue
        | |-MemberExpr <line:12:5, line:15:9> '<bound member function type>' .foo 0xe8a7ac0
        |   | `-CXXMemberCallExpr <line:12:5, line:14:13> 'X' lvalue
        |   |   |-MemberExpr <line:12:5, line:14:9> '<bound member function type>' .foo 0xe8a7ac0
        |   |   | `-CXXMemberCallExpr <line:12:5, line:13:13> 'X' lvalue
        |   |   |   |-MemberExpr <line:12:5, line:13:9> '<bound member function type>' .foo 0xe8a7ac0
 |   |   |   | `-MaterializeTemporaryExpr <line:12:5, col:7> 'X' xvalue
 |   |   |   |   `-CXXFunctionalCastExpr <col:5, col:7> 'X' functional cast to X <NoOp>
        |   |   |   |     `-InitListExpr <col:6, col:7> 'X'
```

I think just using the end location of `CXXMemberCallExpr` rather than begin location can resolve the problem.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJys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