diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-04-18 00:56:58 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-04-18 00:56:58 +0000 |
commit | e867e98314ef5546f4eb2c9c6249f24b739f38ac (patch) | |
tree | e009927c59d59ade11cc940167b75ffeb046d066 /clang/lib/Lex/PPDirectives.cpp | |
parent | 68be3229879ec974678dcf507965d2d78b7c9cf4 (diff) | |
download | bcm5719-llvm-e867e98314ef5546f4eb2c9c6249f24b739f38ac.tar.gz bcm5719-llvm-e867e98314ef5546f4eb2c9c6249f24b739f38ac.zip |
[c++2a] Improve diagnostic for use of declaration from another TU's
global module fragment.
We know that the declaration in question should have been introduced by
a '#include', so try to figure out which one and suggest it. Don't
suggest importing the global module fragment itself!
llvm-svn: 358631
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index b3778c1d6f8..5d5cae5fd0f 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -614,9 +614,16 @@ Preprocessor::getModuleHeaderToIncludeForDiagnostics(SourceLocation IncLoc, SourceLocation Loc) { assert(M && "no module to include"); + // If the context is the global module fragment of some module, we never + // want to return that file; instead, we want the innermost include-guarded + // header that it included. + bool InGlobalModuleFragment = M->Kind == Module::GlobalModuleFragment; + // If we have a module import syntax, we shouldn't include a header to // make a particular module visible. - if (getLangOpts().ObjC) + if ((getLangOpts().ObjC || getLangOpts().CPlusPlusModules || + getLangOpts().ModulesTS) && + !InGlobalModuleFragment) return nullptr; Module *TopM = M->getTopLevelModule(); @@ -633,6 +640,13 @@ Preprocessor::getModuleHeaderToIncludeForDiagnostics(SourceLocation IncLoc, if (!FE) break; + if (InGlobalModuleFragment) { + if (getHeaderSearchInfo().isFileMultipleIncludeGuarded(FE)) + return FE; + Loc = SM.getIncludeLoc(ID); + continue; + } + bool InTextualHeader = false; for (auto Header : HeaderInfo.getModuleMap().findAllModulesForHeader(FE)) { if (!Header.getModule()->isSubModuleOf(TopM)) |