@@ -1978,6 +1978,8 @@ bool LookupResult::isReachableSlow(Sema &SemaRef, NamedDecl *D) {
19781978 if (D->isModulePrivate ())
19791979 return false ;
19801980
1981+ Module *DeclTopModule = DeclModule->getTopLevelModule ();
1982+
19811983 // [module.reach]/p1
19821984 // A translation unit U is necessarily reachable from a point P if U is a
19831985 // module interface unit on which the translation unit containing P has an
@@ -1996,17 +1998,28 @@ bool LookupResult::isReachableSlow(Sema &SemaRef, NamedDecl *D) {
19961998 //
19971999 // Here we only check for the first condition. Since we couldn't see
19982000 // DeclModule if it isn't (transitively) imported.
1999- if (DeclModule-> getTopLevelModule () ->isModuleInterfaceUnit ())
2001+ if (DeclTopModule ->isModuleInterfaceUnit ())
20002002 return true ;
20012003
2002- // [module.reach]/p2
2004+ // [module.reach]/p1,2
2005+ // A translation unit U is necessarily reachable from a point P if U is a
2006+ // module interface unit on which the translation unit containing P has an
2007+ // interface dependency, or the translation unit containing P imports U, in
2008+ // either case prior to P
2009+ //
20032010 // Additional translation units on
20042011 // which the point within the program has an interface dependency may be
20052012 // considered reachable, but it is unspecified which are and under what
20062013 // circumstances.
2007- //
2008- // The decision here is to treat all additional tranditional units as
2009- // unreachable.
2014+ Module *CurrentM = SemaRef.getCurrentModule ();
2015+
2016+ // Directly imported module are necessarily reachable.
2017+ // Since we can't export import a module implementation partition unit, we
2018+ // don't need to count for Exports here.
2019+ if (CurrentM && CurrentM->getTopLevelModule ()->Imports .count (DeclTopModule))
2020+ return true ;
2021+
2022+ // Then we treat all module implementation partition unit as unreachable.
20102023 return false ;
20112024}
20122025
0 commit comments