Skip to content

[[Clang]] Unexpected source location in method chaining #119129

@16bit-ykiko

Description

@16bit-ykiko

Image
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions