@@ -1856,9 +1856,16 @@ DeclContext::lookup(DeclarationName Name) const {
1856
1856
if (getDeclKind () == Decl::LinkageSpec || getDeclKind () == Decl::Export)
1857
1857
return getParent ()->lookup (Name);
1858
1858
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." );
1862
1869
1863
1870
// If we have an external source, ensure that any later redeclarations of this
1864
1871
// context have been loaded, since they may add names to the result of this
@@ -1889,7 +1896,8 @@ DeclContext::lookup(DeclarationName Name) const {
1889
1896
if (!R.second && !R.first ->second .hasExternalDecls ())
1890
1897
return R.first ->second .getLookupResult ();
1891
1898
1892
- if (Source->FindExternalVisibleDeclsByName (this , Name) || !R.second ) {
1899
+ if (Source->FindExternalVisibleDeclsByName (this , Name, OriginalLookupDC) ||
1900
+ !R.second ) {
1893
1901
if (StoredDeclsMap *Map = LookupPtr) {
1894
1902
StoredDeclsMap::iterator I = Map->find (Name);
1895
1903
if (I != Map->end ())
@@ -2115,7 +2123,8 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
2115
2123
if (ExternalASTSource *Source = getParentASTContext ().getExternalSource ())
2116
2124
if (hasExternalVisibleStorage () &&
2117
2125
Map->find (D->getDeclName ()) == Map->end ())
2118
- Source->FindExternalVisibleDeclsByName (this , D->getDeclName ());
2126
+ Source->FindExternalVisibleDeclsByName (this , D->getDeclName (),
2127
+ D->getDeclContext ());
2119
2128
2120
2129
// Insert this declaration into the map.
2121
2130
StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName ()];
0 commit comments