File tree 2 files changed +86
-0
lines changed 2 files changed +86
-0
lines changed Original file line number Diff line number Diff line change @@ -467,6 +467,10 @@ class ASTNodeTraverser
467
467
void VisitBindingDecl (const BindingDecl *D) {
468
468
if (Traversal == TK_IgnoreUnlessSpelledInSource)
469
469
return ;
470
+
471
+ if (const auto *V = D->getHoldingVar ())
472
+ Visit (V);
473
+
470
474
if (const auto *E = D->getBinding ())
471
475
Visit (E);
472
476
}
Original file line number Diff line number Diff line change @@ -1157,6 +1157,46 @@ void decomposition()
1157
1157
f = 42;
1158
1158
}
1159
1159
1160
+ typedef __typeof(sizeof(int)) size_t;
1161
+
1162
+ struct Pair
1163
+ {
1164
+ int x, y;
1165
+ };
1166
+
1167
+ // Note: these utilities are required to force binding to tuple like structure
1168
+ namespace std
1169
+ {
1170
+ template <typename E>
1171
+ struct tuple_size
1172
+ {
1173
+ };
1174
+
1175
+ template <>
1176
+ struct tuple_size<Pair>
1177
+ {
1178
+ static constexpr size_t value = 2;
1179
+ };
1180
+
1181
+ template <size_t I, class T>
1182
+ struct tuple_element
1183
+ {
1184
+ using type = int;
1185
+ };
1186
+
1187
+ };
1188
+
1189
+ template <size_t I>
1190
+ int &&get(Pair &&p);
1191
+
1192
+ void decompTuple()
1193
+ {
1194
+ Pair p{1, 2};
1195
+ auto [a, b] = p;
1196
+
1197
+ a = 3;
1198
+ }
1199
+
1160
1200
)cpp" ,
1161
1201
{" -std=c++20" });
1162
1202
@@ -1492,6 +1532,48 @@ DecompositionDecl ''
1492
1532
|-BindingDecl 'f'
1493
1533
|-BindingDecl 's'
1494
1534
`-BindingDecl 't'
1535
+ )cpp" );
1536
+ }
1537
+
1538
+ {
1539
+ auto FN = ast_matchers::match (
1540
+ functionDecl (hasName (" decompTuple" ),
1541
+ hasDescendant (decompositionDecl ().bind (" decomp" ))),
1542
+ AST2->getASTContext ());
1543
+ EXPECT_EQ (FN.size (), 1u );
1544
+
1545
+ EXPECT_EQ (
1546
+ dumpASTString (TK_AsIs, FN[0 ].getNodeAs <DecompositionDecl>(" decomp" )),
1547
+ R"cpp(
1548
+ DecompositionDecl ''
1549
+ |-CXXConstructExpr
1550
+ | `-ImplicitCastExpr
1551
+ | `-DeclRefExpr 'p'
1552
+ |-BindingDecl 'a'
1553
+ | |-VarDecl 'a'
1554
+ | | `-CallExpr
1555
+ | | |-ImplicitCastExpr
1556
+ | | | `-DeclRefExpr 'get'
1557
+ | | `-ImplicitCastExpr
1558
+ | | `-DeclRefExpr ''
1559
+ | `-DeclRefExpr 'a'
1560
+ `-BindingDecl 'b'
1561
+ |-VarDecl 'b'
1562
+ | `-CallExpr
1563
+ | |-ImplicitCastExpr
1564
+ | | `-DeclRefExpr 'get'
1565
+ | `-ImplicitCastExpr
1566
+ | `-DeclRefExpr ''
1567
+ `-DeclRefExpr 'b'
1568
+ )cpp" );
1569
+
1570
+ EXPECT_EQ (dumpASTString (TK_IgnoreUnlessSpelledInSource,
1571
+ FN[0 ].getNodeAs <DecompositionDecl>(" decomp" )),
1572
+ R"cpp(
1573
+ DecompositionDecl ''
1574
+ |-DeclRefExpr 'p'
1575
+ |-BindingDecl 'a'
1576
+ `-BindingDecl 'b'
1495
1577
)cpp" );
1496
1578
}
1497
1579
}
You can’t perform that action at this time.
0 commit comments