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

    <tr>
        <th>Summary</th>
        <td>
            RecursiveASTVisitor does not traverse field references in CXXCtorInitializer by default
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          varungandhi-src
      </td>
    </tr>
</table>

<pre>
    The default code looks like this right now:

```cpp
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
 CXXCtorInitializer *Init) {
  if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));

  if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
 TRY_TO(TraverseStmt(Init->getInit()));

  return true;
}
```

It seems like the fields are not being visited, because the correct AST node is not available, as CXXCtorInitializer stores a FieldDecl instead of storing a MemberExpr or a DeclRefExpr.

```
class CXXCtorInitializer final {
  /// Either the base class name/delegating constructor type (stored as
  /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
  /// (IndirectFieldDecl*) being initialized.
 llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
 Initializee;
```

Would it make sense to change the representation of CXXCtorInitializer to instead store some Expr node instead of *FieldDecl node directly, at the cost of increased memory usage, and a bit more indirection? Alternately, is there an equivalent of TypeLoc but for Decls which could be used here instead as a lighter alternative to DeclRefExpr which doesn't require any additional allocations? (I don't see any class named `DeclLoc`, but I may have missed something.)

I also understand if you want to close this issue as a Won't Fix, since anyone can override the default implementation to additionally traverse `FieldDecl/IndirectFieldDecl` in a custom way.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVl1v47YS_TX0yyCGItmO_eAHrxMDAe7Fvdi43e1TQZEjiV2KdMmRs-6vL4aUP3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