diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -481,6 +481,7 @@ ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); + ExpectedDecl VisitBindingDecl(BindingDecl *D); ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); @@ -2274,6 +2275,36 @@ return ToD; } +ExpectedDecl ASTNodeImporter::VisitBindingDecl(BindingDecl *D) { + DeclContext *DC, *LexicalDC; + DeclarationName Name; + SourceLocation Loc; + NamedDecl *ToND; + if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc)) + return std::move(Err); + if (ToND) + return ToND; + + Error Err = Error::success(); + auto ToType = importChecked(Err, D->getType()); + auto ToBinding = importChecked(Err, D->getBinding()); + auto ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl()); + if (Err) + return std::move(Err); + + BindingDecl *ToD; + if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc, + Name.getAsIdentifierInfo())) + return ToD; + + ToD->setLexicalDeclContext(LexicalDC); + DC->addDeclInternal(ToD); + ToD->setBinding(ToType, ToBinding); + ToD->setDecomposedDecl(ToDecomposedDecl); + + return ToD; +} + ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { ExpectedSLoc LocOrErr = import(D->getLocation()); if (!LocOrErr) diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -868,6 +868,14 @@ namespaceDecl(has(usingShadowDecl()))); } +TEST_P(ImportDecl, ImportBindingDecl) { + MatchVerifier Verifier; + testImport("int a[2] = {1, 2};" + "auto [declToImport, x] = a;", + Lang_CXX17, "", Lang_CXX17, Verifier, + bindingDecl(hasType(asString("int")))); +} + TEST_P(ImportExpr, ImportUnresolvedLookupExpr) { MatchVerifier Verifier; testImport("template int foo();"