Comment #1 on pull request 1072 by kimgr: Fix autocast to reference
https://github.com/include-what-you-use/include-what-you-use/pull/1072
Nice, thanks!
I'm not sure about the approach -- the way I understand it, `Traverse` overrides are only necessary to customize the actual AST _traversal_ (e.g. visiting more nodes than the base RAV does, or skipping over nodes that it normally visits), which shouldn't be the case here.
The AST from the test looks like this:
```
tests/cxx/iwyu_stricter_than_cpp-d2.h:17:34: (2) [ CompoundStmt ] CompoundStmt 0x5572d77b9a28
|-ExprWithCleanups 0x5572d77b9860 'void'
| `-CallExpr 0x5572d77b94c0 'void'
| |-ImplicitCastExpr 0x5572d77b94a8 'void (*)(struct IndirectStruct2)' <FunctionToPointerDecay>
| | `-DeclRefExpr 0x5572d77b9458 'void (struct IndirectStruct2)' lvalue Function 0x5572d77b7710 'TwiceDeclaredFunction' 'void (struct IndirectStruct2)'
| `-CXXConstructExpr 0x5572d77b9830 'struct IndirectStruct2' 'void (struct IndirectStruct2 &&) noexcept' elidable
| `-MaterializeTemporaryExpr 0x5572d77b9708 'struct IndirectStruct2' xvalue
| `-ImplicitCastExpr 0x5572d77b95e0 'struct IndirectStruct2' <ConstructorConversion>
| `-CXXConstructExpr 0x5572d77b95b0 'struct IndirectStruct2' 'void (int)'
| `-IntegerLiteral 0x5572d77b9118 'int' 1
`-ExprWithCleanups 0x5572d77b99e0 'void'
`-CallExpr 0x5572d77b9940 'void'
|-ImplicitCastExpr 0x5572d77b9928 'void (*)(const struct IndirectStruct2 &)' <FunctionToPointerDecay>
| `-DeclRefExpr 0x5572d77b98e0 'void (const struct IndirectStruct2 &)' lvalue Function 0x5572d77b7858 'TwiceDeclaredRefFunction' 'void (const struct IndirectStruct2 &)'
`-MaterializeTemporaryExpr 0x5572d77b99c8 'const struct IndirectStruct2' lvalue
`-CXXConstructExpr 0x5572d77b9998 'const struct IndirectStruct2' 'void (int)'
`-IntegerLiteral 0x5572d77b98c0 'int' 1
```
so it seems to me there are two tree shapes we need to take into account:
* For `TwiceDeclaredFunction`: `CallExpr` / `CXXConstructExpr` / `MaterializeTemporaryExpr` / `ImplicitCastExpr(ConstructorConversion)` / `CXXConstructExpr` (handled today in `VisitCastExpr`)
* For `TwiceDeclaredRefFunction`: `CallExpr` / `MaterializeTemporaryExpr` / `CXXConstructExpr`
I wonder if it would make sense to work on all this in `VisitCXXConstructExpr` instead, and look back up the tree for both shapes? I'm not saying that's the way to go, I'm just thinking out loud. I don't have a good idea for how to look for tree shapes other than by looping up the `ASTNode` tree doing `IsA<NodeType>`, but it seems it would be nice to be able to express things like that as a single expression.