In clang-tidy there is the readability-isolate-declaration check. I am trying to do something similar for field declarations.
Let us say that we have the following
typedef struct s{
int x,y;
}s;
If we check the above example in clang-query we get something like
CXXRecordDecl 0x555e28564740 <<source>:1:9, line:4:1> line:1:16 struct s definition
|-DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal
| |-DefaultConstructor exists trivial needs_implicit
| |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveConstructor exists simple trivial needs_implicit
| |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveAssignment exists simple trivial needs_implicit
| `-Destructor simple irrelevant trivial needs_implicit
|-CXXRecordDecl 0x555e28564858 <col:9, col:16> col:16 implicit struct s
|-FieldDecl 0x555e28564900 <line:2:5, col:9> col:9 x 'int'
-FieldDecl 0x555e28564968 <col:5, col:11> col:11 y 'int'
Here I get 2 different FieldDecls for x and y. I also get 2 FieldDecls in the following case
typedef struct s{
int x;
int y;
}s;
CXXRecordDecl 0x5648bcf47740 <<source>:1:9, line:5:1> line:1:16 struct s definition
|-DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal
| |-DefaultConstructor exists trivial needs_implicit
| |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveConstructor exists simple trivial needs_implicit
| |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveAssignment exists simple trivial needs_implicit
| `-Destructor simple irrelevant trivial needs_implicit
|-CXXRecordDecl 0x5648bcf47858 <col:9, col:16> col:16 implicit struct s
|-FieldDecl 0x5648bcf47900 <line:2:5, col:9> col:9 x 'int'
`-FieldDecl 0x5648bcf47968 <line:3:5, col:9> col:9 y 'int'
This is nearly identical. How can someone distinguish between the two cases based on the AST?