@@ -1856,9 +1856,16 @@ DeclContext::lookup(DeclarationName Name) const {
18561856 if (getDeclKind () == Decl::LinkageSpec || getDeclKind () == Decl::Export)
18571857 return getParent ()->lookup (Name);
18581858
1859- const DeclContext *PrimaryContext = getPrimaryContext ();
1860- if (PrimaryContext != this )
1861- return PrimaryContext->lookup (Name);
1859+ return getPrimaryContext ()->lookupImpl (Name, this );
1860+ }
1861+
1862+ DeclContext::lookup_result
1863+ DeclContext::lookupImpl (DeclarationName Name,
1864+ const DeclContext *OriginalLookupDC) const {
1865+ assert (this == getPrimaryContext () &&
1866+ " lookupImpl should only be called with primary DC!" );
1867+ assert (getDeclKind () != Decl::LinkageSpec && getDeclKind () != Decl::Export &&
1868+ " We shouldn't lookup in transparent DC." );
18621869
18631870 // If we have an external source, ensure that any later redeclarations of this
18641871 // context have been loaded, since they may add names to the result of this
@@ -1889,7 +1896,8 @@ DeclContext::lookup(DeclarationName Name) const {
18891896 if (!R.second && !R.first ->second .hasExternalDecls ())
18901897 return R.first ->second .getLookupResult ();
18911898
1892- if (Source->FindExternalVisibleDeclsByName (this , Name) || !R.second ) {
1899+ if (Source->FindExternalVisibleDeclsByName (this , Name, OriginalLookupDC) ||
1900+ !R.second ) {
18931901 if (StoredDeclsMap *Map = LookupPtr) {
18941902 StoredDeclsMap::iterator I = Map->find (Name);
18951903 if (I != Map->end ())
@@ -2115,7 +2123,8 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
21152123 if (ExternalASTSource *Source = getParentASTContext ().getExternalSource ())
21162124 if (hasExternalVisibleStorage () &&
21172125 Map->find (D->getDeclName ()) == Map->end ())
2118- Source->FindExternalVisibleDeclsByName (this , D->getDeclName ());
2126+ Source->FindExternalVisibleDeclsByName (this , D->getDeclName (),
2127+ D->getDeclContext ());
21192128
21202129 // Insert this declaration into the map.
21212130 StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName ()];
0 commit comments