| Issue |
61602
|
| Summary |
RecursiveASTVisitor does not traverse field references in CXXCtorInitializer by default
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
varungandhi-src
|
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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs