@@ -6052,7 +6052,7 @@ TEST_P(ASTImporterLookupTableTest, EnumConstantDecl) {
60526052 EXPECT_EQ (*Res.begin (), A);
60536053}
60546054
6055- TEST_P (ASTImporterLookupTableTest, LookupSearchesInTheWholeRedeclChain ) {
6055+ TEST_P (ASTImporterLookupTableTest, LookupSearchesInActualNamespaceOnly ) {
60566056 TranslationUnitDecl *ToTU = getToTuDecl (
60576057 R"(
60586058 namespace N {
@@ -6062,7 +6062,9 @@ TEST_P(ASTImporterLookupTableTest, LookupSearchesInTheWholeRedeclChain) {
60626062 }
60636063 )" ,
60646064 Lang_CXX03);
6065- auto *N1 =
6065+ auto *N1 = FirstDeclMatcher<NamespaceDecl>().match (
6066+ ToTU, namespaceDecl (hasName (" N" )));
6067+ auto *N2 =
60666068 LastDeclMatcher<NamespaceDecl>().match (ToTU, namespaceDecl (hasName (" N" )));
60676069 auto *A = FirstDeclMatcher<VarDecl>().match (ToTU, varDecl (hasName (" A" )));
60686070 DeclarationName Name = A->getDeclName ();
@@ -6071,6 +6073,7 @@ TEST_P(ASTImporterLookupTableTest, LookupSearchesInTheWholeRedeclChain) {
60716073 auto Res = LT.lookup (N1, Name);
60726074 ASSERT_EQ (Res.size (), 1u );
60736075 EXPECT_EQ (*Res.begin (), A);
6076+ EXPECT_TRUE (LT.lookup (N2, Name).empty ());
60746077}
60756078
60766079TEST_P (ASTImporterOptionSpecificTestBase,
@@ -10170,6 +10173,151 @@ TEST_P(ImportTemplateParmDeclDefaultValue,
1017010173 FromD, FromDInherited);
1017110174}
1017210175
10176+ TEST_P (ASTImporterOptionSpecificTestBase, ImportIntoReopenedNamespaceNoMatch1) {
10177+ const char *ToCode =
10178+ R"(
10179+ namespace a {
10180+ }
10181+ namespace a {
10182+ struct X { int A; };
10183+ }
10184+ )" ;
10185+ Decl *ToTU = getToTuDecl (ToCode, Lang_CXX11);
10186+ const char *Code =
10187+ R"(
10188+ namespace a {
10189+ struct X { char A; };
10190+ }
10191+ )" ;
10192+ Decl *FromTU = getTuDecl (Code, Lang_CXX11);
10193+ auto *FromX = FirstDeclMatcher<CXXRecordDecl>().match (
10194+ FromTU, cxxRecordDecl (hasName (" X" )));
10195+ auto *ImportedX = Import (FromX, Lang_CXX11);
10196+ EXPECT_FALSE (ImportedX);
10197+ }
10198+
10199+ TEST_P (ASTImporterOptionSpecificTestBase, ImportIntoReopenedNamespaceNoMatch2) {
10200+ const char *ToCode =
10201+ R"(
10202+ namespace a {
10203+ struct X { int A; };
10204+ }
10205+ namespace a {
10206+ }
10207+ )" ;
10208+ Decl *ToTU = getToTuDecl (ToCode, Lang_CXX11);
10209+ const char *Code =
10210+ R"(
10211+ namespace a {
10212+ struct X { char A; };
10213+ }
10214+ )" ;
10215+ Decl *FromTU = getTuDecl (Code, Lang_CXX11);
10216+ auto *FromX = FirstDeclMatcher<CXXRecordDecl>().match (
10217+ FromTU, cxxRecordDecl (hasName (" X" )));
10218+ auto *ImportedX = Import (FromX, Lang_CXX11);
10219+ EXPECT_FALSE (ImportedX);
10220+ }
10221+
10222+ TEST_P (ASTImporterOptionSpecificTestBase, ImportIntoReopenedNamespaceMatch1) {
10223+ const char *ToCode =
10224+ R"(
10225+ namespace a {
10226+ }
10227+ namespace a {
10228+ struct X { int A; };
10229+ }
10230+ )" ;
10231+ Decl *ToTU = getToTuDecl (ToCode, Lang_CXX11);
10232+ const char *Code =
10233+ R"(
10234+ namespace a {
10235+ struct X { int A; };
10236+ }
10237+ )" ;
10238+ Decl *FromTU = getTuDecl (Code, Lang_CXX11);
10239+ auto *FromX = FirstDeclMatcher<CXXRecordDecl>().match (
10240+ FromTU, cxxRecordDecl (hasName (" X" )));
10241+ auto *ToX = FirstDeclMatcher<CXXRecordDecl>().match (
10242+ ToTU, cxxRecordDecl (hasName (" X" )));
10243+ auto *ImportedX = Import (FromX, Lang_CXX11);
10244+ EXPECT_EQ (ImportedX, ToX);
10245+ }
10246+
10247+ TEST_P (ASTImporterOptionSpecificTestBase, ImportIntoReopenedNamespaceMatch2) {
10248+ const char *ToCode =
10249+ R"(
10250+ namespace a {
10251+ struct X { int A; };
10252+ }
10253+ namespace a {
10254+ }
10255+ )" ;
10256+ Decl *ToTU = getToTuDecl (ToCode, Lang_CXX11);
10257+ const char *Code =
10258+ R"(
10259+ namespace a {
10260+ struct X { int A; };
10261+ }
10262+ )" ;
10263+ Decl *FromTU = getTuDecl (Code, Lang_CXX11);
10264+ auto *FromX = FirstDeclMatcher<CXXRecordDecl>().match (
10265+ FromTU, cxxRecordDecl (hasName (" X" )));
10266+ auto *ToX = FirstDeclMatcher<CXXRecordDecl>().match (
10267+ ToTU, cxxRecordDecl (hasName (" X" )));
10268+ auto *ImportedX = Import (FromX, Lang_CXX11);
10269+ EXPECT_EQ (ImportedX, ToX);
10270+ }
10271+
10272+ TEST_P (ASTImporterLookupTableTest, PrimaryDCChangeAtImport) {
10273+ const char *ToCode =
10274+ R"(
10275+ template <class T>
10276+ struct X;
10277+ )" ;
10278+ Decl *ToTU = getToTuDecl (ToCode, Lang_CXX11);
10279+ auto *ToX = FirstDeclMatcher<ClassTemplateDecl>().match (
10280+ ToTU, classTemplateDecl (hasName (" X" )));
10281+ NamedDecl *ToParm = ToX->getTemplateParameters ()->getParam (0 );
10282+ DeclContext *OldPrimaryDC = ToX->getTemplatedDecl ()->getPrimaryContext ();
10283+ ASSERT_EQ (ToParm->getDeclContext (), ToX->getTemplatedDecl ());
10284+ ASSERT_EQ (SharedStatePtr->getLookupTable ()
10285+ ->lookup (ToX->getTemplatedDecl (), ToParm->getDeclName ())
10286+ .size (),
10287+ 1u );
10288+ ASSERT_TRUE (SharedStatePtr->getLookupTable ()->contains (
10289+ ToX->getTemplatedDecl (), ToParm));
10290+
10291+ const char *Code =
10292+ R"(
10293+ template <class T>
10294+ struct X;
10295+ template <class T>
10296+ struct X {};
10297+ )" ;
10298+ Decl *FromTU = getTuDecl (Code, Lang_CXX11);
10299+ auto *FromX = LastDeclMatcher<ClassTemplateDecl>().match (
10300+ FromTU, classTemplateDecl (hasName (" X" )));
10301+
10302+ auto *ImportedX = Import (FromX, Lang_CXX11);
10303+
10304+ EXPECT_TRUE (ImportedX);
10305+ EXPECT_EQ (ImportedX->getTemplateParameters ()->getParam (0 )->getDeclContext (),
10306+ ImportedX->getTemplatedDecl ());
10307+
10308+ // ToX did not change at the import.
10309+ // Verify that primary context has changed after import of class definition.
10310+ DeclContext *NewPrimaryDC = ToX->getTemplatedDecl ()->getPrimaryContext ();
10311+ EXPECT_NE (OldPrimaryDC, NewPrimaryDC);
10312+ // The lookup table should not be different than it was before.
10313+ EXPECT_EQ (SharedStatePtr->getLookupTable ()
10314+ ->lookup (ToX->getTemplatedDecl (), ToParm->getDeclName ())
10315+ .size (),
10316+ 1u );
10317+ EXPECT_TRUE (SharedStatePtr->getLookupTable ()->contains (
10318+ ToX->getTemplatedDecl (), ToParm));
10319+ }
10320+
1017310321TEST_P (ASTImporterOptionSpecificTestBase,
1017410322 ExistingUndeclaredImportDeclaredFriend) {
1017510323 Decl *ToTU = getToTuDecl (
0 commit comments