<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/122257>122257</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
libclang: how to visit implicit declarations.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
phadej
</td>
</tr>
</table>
<pre>
Consider simple `u.h` header
```c
union u {
int big;
struct {
char small1;
char small2;
};
};
```
`clang -Xclang -ast-dump -fsyntax-only` prints
```
`-RecordDecl 0xeba4a10 <u.h:1:1, line:7:1> line:1:7 union u definition
|-FieldDecl 0xeba4ac8 <line:2:2, col:6> col:6 big 'int'
|-RecordDecl 0xeba4b18 <line:3:2, line:6:2> line:3:2 struct definition
| |-FieldDecl 0xeba4bd0 <line:4:3, col:8> col:8 small1 'char'
| `-FieldDecl 0xeba4c30 <line:5:3, col:8> col:8 small2 'char'
|-FieldDecl 0xeba4cd8 <line:3:2> col:2 implicit 'struct u::(anonymous at u.h:3:2)'
|-IndirectFieldDecl 0xeba4d38 <line:4:8> col:8 implicit small1 'char'
| |-Field 0xeba4cd8 '' 'struct u::(anonymous at u.h:3:2)'
| `-Field 0xeba4bd0 'small1' 'char'
`-IndirectFieldDecl 0xeba4d90 <line:5:8> col:8 implicit small2 'char'
|-Field 0xeba4cd8 '' 'struct u::(anonymous at u.h:3:2)'
`-Field 0xeba4c30 'small2' 'char'
```
Notice, there is implicit fielddecl for `struct u::(anonymous ...)` as well as (implicit?) `IndirectFieldDecl`s.
However, when using `libclang` interface, in particular, [clang_visitChildren](https://clang.llvm.org/doxygen/group__CINDEX__CURSOR__TRAVERSAL.html#ga5d0a813d937e1a7dcc35f206ad1f7a91) only explicit declarations are visiible. I.e. we can only see first two declarations, `big 'int'` and `struct definition`.
In some cases it's very inconvenient to work with source code with tagless and/or field-nameless substructures.
Is there a way to also traverse implicit declarations?
</pre>
<img width="1" height="1"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