Extract `clang::DecompositionDecl` for structured bindings
A structured binding declaration can declare variables at global/namespace scope. But it is not part of the clang::VarDecl, but the clang::DecompositionDecl instead, which itself contains multiple clang::BindingDecls.
int a[2]{};
const auto& [b, c] = a;
TranslationUnitDecl
|-VarDecl <line:1:1, col:10> col:5 used a 'int[2]' listinit
| `-InitListExpr <col:9, col:10> 'int[2]'
| `-array_filler: ImplicitValueInitExpr 0x55da82684710 'int'
|-BindingDecl <line:2:14> col:14 b 'const int'
| `-ArraySubscriptExpr <col:14> 'const int' lvalue
| |-ImplicitCastExpr <col:14> 'const int *' <ArrayToPointerDecay>
| | `-DeclRefExpr <col:14> 'const int[2]':'const int[2]' lvalue Decomposition 0x55da826848d8 '' 'const int &[2]' non_odr_use_constant
| `-IntegerLiteral <col:14> 'int' 0
|-BindingDecl <col:17> col:17 c 'const int'
| `-ArraySubscriptExpr <col:17> 'const int' lvalue
| |-ImplicitCastExpr <col:17> 'const int *' <ArrayToPointerDecay>
| | `-DeclRefExpr <col:17> 'const int[2]':'const int[2]' lvalue Decomposition 0x55da826848d8 '' 'const int &[2]' non_odr_use_constant
| `-IntegerLiteral <col:17> 'int' 1
`-DecompositionDecl <col:1, col:22> col:13 referenced 'const int &[2]' cinit
|-ImplicitCastExpr <col:22> 'const int[2]':'const int[2]' lvalue <NoOp>
| `-DeclRefExpr <col:22> 'int[2]' lvalue Var 0x55da826845d8 'a' 'int[2]'
|-BindingDecl <col:14> col:14 b 'const int'
| `-ArraySubscriptExpr <col:14> 'const int' lvalue
| |-ImplicitCastExpr <col:14> 'const int *' <ArrayToPointerDecay>
| | `-DeclRefExpr <col:14> 'const int[2]':'const int[2]' lvalue Decomposition 0x55da826848d8 '' 'const int &[2]' non_odr_use_constant
| `-IntegerLiteral <col:14> 'int' 0
`-BindingDecl <col:17> col:17 c 'const int'
`-ArraySubscriptExpr <col:17> 'const int' lvalue
|-ImplicitCastExpr <col:17> 'const int *' <ArrayToPointerDecay>
| `-DeclRefExpr <col:17> 'const int[2]':'const int[2]' lvalue Decomposition 0x55da826848d8 '' 'const int &[2]' non_odr_use_constant
`-IntegerLiteral <col:17> 'int' 1
Docu: clang::DecompositionDecl
Example: https://structbind.compiler-explorer.com/z/4sa3vaKb7
I mean.. that's going deep into the weeds :) Adding a new top level object is not a trivial exercise. I would like to polish up the top level objects we already have before we go creating new ones. But this is helpful :)
I am not sure if I will ever pick up this issue. But I at least wanted to report my finding :)
Yeah its good