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 @@ -3632,6 +3632,10 @@ auto ToInitializer = importChecked(Err, D->getInClassInitializer()); if (Err) return std::move(Err); + const Type *ToCapturedVLAType = nullptr; + if (Error Err = Importer.importInto( + ToCapturedVLAType, cast_or_null(D->getCapturedVLAType()))) + return std::move(Err); FieldDecl *ToField; if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, @@ -3645,6 +3649,8 @@ if (ToInitializer) ToField->setInClassInitializer(ToInitializer); ToField->setImplicit(D->isImplicit()); + if (ToCapturedVLAType) + ToField->setCapturedVLAType(cast(ToCapturedVLAType)); LexicalDC->addDeclInternal(ToField); return ToField; } 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 @@ -6261,6 +6261,25 @@ EXPECT_TRUE(To2); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportOfCapturedVLAType) { + Decl *FromTU = getTuDecl( + R"( + void declToImport(int N) { + int VLA[N]; + [&VLA] {}; // FieldDecl inside the lambda. + } + )", + Lang_CXX14); + auto *FromFD = FirstDeclMatcher().match(FromTU, fieldDecl()); + ASSERT_TRUE(FromFD); + ASSERT_TRUE(FromFD->hasCapturedVLAType()); + + auto *ToFD = Import(FromFD, Lang_CXX14); + EXPECT_TRUE(ToFD); + EXPECT_TRUE(ToFD->hasCapturedVLAType()); + EXPECT_NE(FromFD->getCapturedVLAType(), ToFD->getCapturedVLAType()); +} + INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions, );