@@ -10492,6 +10492,79 @@ TEST_P(ASTImporterOptionSpecificTestBase,
1049210492 EXPECT_EQ(ToFr1Imp, ToFr1);
1049310493}
1049410494
10495+ struct ImportAndMergeAnonymousNamespace
10496+ : public ASTImporterOptionSpecificTestBase {
10497+ protected:
10498+ void test(const char *ToCode, const char *FromCode) {
10499+ Decl *ToTU = getToTuDecl(ToCode, Lang_CXX11);
10500+ Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
10501+ auto *FromNS = FirstDeclMatcher<NamespaceDecl>().match(
10502+ FromTU, namespaceDecl(isAnonymous()));
10503+ auto *ToNS = FirstDeclMatcher<NamespaceDecl>().match(
10504+ ToTU, namespaceDecl(isAnonymous()));
10505+ auto *FromF = FirstDeclMatcher<FunctionDecl>().match(
10506+ FromTU, functionDecl(hasName("f")));
10507+ auto *ImportedF = Import(FromF, Lang_CXX11);
10508+ EXPECT_TRUE(ImportedF);
10509+ EXPECT_EQ(ImportedF->getDeclContext(), ToNS);
10510+ auto *ImportedNS = Import(FromNS, Lang_CXX11);
10511+ EXPECT_EQ(ImportedNS, ToNS);
10512+ }
10513+ };
10514+
10515+ TEST_P(ImportAndMergeAnonymousNamespace, NamespaceInTU) {
10516+ const char *ToCode =
10517+ R"(
10518+ namespace {
10519+ }
10520+ )";
10521+ const char *FromCode =
10522+ R"(
10523+ namespace {
10524+ void f();
10525+ }
10526+ )";
10527+ test(ToCode, FromCode);
10528+ }
10529+
10530+ TEST_P(ImportAndMergeAnonymousNamespace, NamespaceInLinkageSpec) {
10531+ const char *ToCode =
10532+ R"(
10533+ extern "C" {
10534+ namespace {
10535+ }
10536+ }
10537+ )";
10538+ const char *FromCode =
10539+ R"(
10540+ extern "C" {
10541+ namespace {
10542+ void f();
10543+ }
10544+ }
10545+ )";
10546+ test(ToCode, FromCode);
10547+ }
10548+
10549+ TEST_P(ImportAndMergeAnonymousNamespace, NamespaceInNamespace) {
10550+ const char *ToCode =
10551+ R"(
10552+ namespace X {
10553+ namespace {
10554+ }
10555+ }
10556+ )";
10557+ const char *FromCode =
10558+ R"(
10559+ namespace X {
10560+ namespace {
10561+ void f();
10562+ }
10563+ }
10564+ )";
10565+ test(ToCode, FromCode);
10566+ }
10567+
1049510568INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
1049610569 DefaultTestValuesForRunOptions);
1049710570
@@ -10578,6 +10651,9 @@ INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportMatrixType,
1057810651INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportTemplateParmDeclDefaultValue,
1057910652 DefaultTestValuesForRunOptions);
1058010653
10654+ ISTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportAndMergeAnonymousNamespace,
10655+ DefaultTestValuesForRunOptions);
10656+
1058110657// FIXME: Make ImportOpenCLPipe test work.
1058210658// INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportOpenCLPipe,
1058310659// DefaultTestValuesForRunOptions);
0 commit comments