@@ -1174,6 +1174,12 @@ struct Pair
11741174 int x, y;
11751175};
11761176
1177+ // Tuple-like structure with a `get` method that has a default argument.
1178+ struct Pair2
1179+ {
1180+ int x, y;
1181+ };
1182+
11771183// Note: these utilities are required to force binding to tuple like structure
11781184namespace std
11791185{
@@ -1188,6 +1194,12 @@ namespace std
11881194 static constexpr size_t value = 2;
11891195 };
11901196
1197+ template <>
1198+ struct tuple_size<Pair2>
1199+ {
1200+ static constexpr size_t value = 2;
1201+ };
1202+
11911203 template <size_t I, class T>
11921204 struct tuple_element
11931205 {
@@ -1199,12 +1211,17 @@ namespace std
11991211template <size_t I>
12001212int &&get(Pair &&p);
12011213
1214+ template <size_t I>
1215+ int &&get(Pair2 &&p, int unused = 0);
1216+
12021217void decompTuple()
12031218{
12041219 Pair p{1, 2};
12051220 auto [a, b] = p;
12061221
12071222 a = 3;
1223+
1224+ auto [c, d] = Pair2{3, 4};
12081225}
12091226
12101227)cpp" ,
@@ -1586,6 +1603,56 @@ DecompositionDecl ''
15861603|-DeclRefExpr 'p'
15871604|-BindingDecl 'a'
15881605`-BindingDecl 'b'
1606+ )cpp" );
1607+ }
1608+
1609+ {
1610+ auto FN = ast_matchers::match (
1611+ functionDecl (hasName (" decompTuple" ), hasDescendant (callExpr (hasAncestor (varDecl (hasName (" a" ),
1612+ hasAncestor (bindingDecl ())))).bind (" decomp_call" ))),
1613+ AST2->getASTContext ());
1614+ EXPECT_EQ (FN.size (), 1u );
1615+
1616+ EXPECT_EQ (
1617+ dumpASTString (TK_AsIs, FN[0 ].getNodeAs <CallExpr>(" decomp_call" )),
1618+ R"cpp(
1619+ CallExpr
1620+ |-ImplicitCastExpr
1621+ | `-DeclRefExpr 'get'
1622+ `-ImplicitCastExpr
1623+ `-DeclRefExpr ''
1624+ )cpp" );
1625+
1626+ EXPECT_EQ (dumpASTString (TK_IgnoreUnlessSpelledInSource,
1627+ FN[0 ].getNodeAs <CallExpr>(" decomp_call" )),
1628+ R"cpp(
1629+ DeclRefExpr ''
1630+ )cpp" );
1631+ }
1632+
1633+ {
1634+ auto FN = ast_matchers::match (
1635+ functionDecl (hasName (" decompTuple" ), hasDescendant (callExpr (hasAncestor (varDecl (hasName (" c" ),
1636+ hasAncestor (bindingDecl ())))).bind (" decomp_call_with_default" ))),
1637+ AST2->getASTContext ());
1638+ EXPECT_EQ (FN.size (), 1u );
1639+
1640+ EXPECT_EQ (dumpASTString (TK_AsIs, FN[0 ].getNodeAs <CallExpr>(
1641+ " decomp_call_with_default" )),
1642+ R"cpp(
1643+ CallExpr
1644+ |-ImplicitCastExpr
1645+ | `-DeclRefExpr 'get'
1646+ |-ImplicitCastExpr
1647+ | `-DeclRefExpr ''
1648+ `-CXXDefaultArgExpr
1649+ `-IntegerLiteral
1650+ )cpp" );
1651+
1652+ EXPECT_EQ (dumpASTString (TK_IgnoreUnlessSpelledInSource,
1653+ FN[0 ].getNodeAs <CallExpr>(" decomp_call_with_default" )),
1654+ R"cpp(
1655+ DeclRefExpr ''
15891656)cpp" );
15901657 }
15911658}
0 commit comments