Index: clang/unittests/AST/ASTTraverserTest.cpp =================================================================== --- clang/unittests/AST/ASTTraverserTest.cpp +++ clang/unittests/AST/ASTTraverserTest.cpp @@ -1077,6 +1077,8 @@ } auto AST2 = buildASTFromCodeWithArgs(R"cpp( +#include + struct Simple { }; struct Other { @@ -1157,6 +1159,14 @@ f = 42; } +void decompTuple() +{ + std::tuple tpl(2.0, 'a', 1); + auto [a, b, c] = tpl; + + a = 3.5; +} + )cpp", {"-std=c++20"}); @@ -1492,6 +1502,57 @@ |-BindingDecl 'f' |-BindingDecl 's' `-BindingDecl 't' +)cpp"); + } + + { + auto FN = ast_matchers::match( + functionDecl(hasName("decompTuple"), + hasDescendant(decompositionDecl().bind("decomp"))), + AST2->getASTContext()); + EXPECT_EQ(FN.size(), 1u); + + EXPECT_EQ( + dumpASTString(TK_AsIs, FN[0].getNodeAs("decomp")), + R"cpp( +DecompositionDecl '' +|-CXXConstructExpr +| `-ImplicitCastExpr +| `-DeclRefExpr 'tpl' +|-BindingDecl 'a' +| |-VarDecl 'a' +| | `-CallExpr +| | |-ImplicitCastExpr +| | | `-DeclRefExpr 'get' +| | `-ImplicitCastExpr +| | `-DeclRefExpr '' +| `-DeclRefExpr 'a' +|-BindingDecl 'b' +| |-VarDecl 'b' +| | `-CallExpr +| | |-ImplicitCastExpr +| | | `-DeclRefExpr 'get' +| | `-ImplicitCastExpr +| | `-DeclRefExpr '' +| `-DeclRefExpr 'b' +`-BindingDecl 'c' + |-VarDecl 'c' + | `-CallExpr + | |-ImplicitCastExpr + | | `-DeclRefExpr 'get' + | `-ImplicitCastExpr + | `-DeclRefExpr '' + `-DeclRefExpr 'c' +)cpp"); + + EXPECT_EQ(dumpASTString(TK_IgnoreUnlessSpelledInSource, + FN[0].getNodeAs("decomp")), + R"cpp( +DecompositionDecl '' +|-DeclRefExpr 'tpl' +|-BindingDecl 'a' +|-BindingDecl 'b' +`-BindingDecl 'c' )cpp"); } }