diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-11-17 23:32:01 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-11-17 23:32:01 +0000 |
commit | 752ada870d7bc5759a80abde286c77e95ef77fb6 (patch) | |
tree | 78ed50e92dbc86db3fa3f175bd7e8a9ac2781995 /clang/lib/Sema/SemaDecl.cpp | |
parent | 70507e59fe06e187045ad1c6abd518495683f038 (diff) | |
download | bcm5719-llvm-752ada870d7bc5759a80abde286c77e95ef77fb6.tar.gz bcm5719-llvm-752ada870d7bc5759a80abde286c77e95ef77fb6.zip |
[modules] When a #include is mapped to a module import and appears somewhere
other than the top level, we issue an error. This breaks a fair amount of C++
code wrapping C libraries, where the C library is #included within a namespace
/ extern "C" combination, because the C library (probably) includes C++
standard library headers which may be within modules.
Without modules, this setup is harmless if (and *only* if) the corresponding
standard library module was already included outside the namespace, so
downgrade the error to a default-error extension in that case, so that it can
be selectively disabled for such misbehaving libraries.
llvm-svn: 253398
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e4e48a69ab8..4e2616ebe20 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14500,8 +14500,8 @@ Decl *Sema::ActOnFileScopeAsmDecl(Expr *expr, } static void checkModuleImportContext(Sema &S, Module *M, - SourceLocation ImportLoc, - DeclContext *DC) { + SourceLocation ImportLoc, DeclContext *DC, + bool FromInclude = false) { SourceLocation ExternCLoc; if (auto *LSD = dyn_cast<LinkageSpecDecl>(DC)) { @@ -14520,7 +14520,9 @@ static void checkModuleImportContext(Sema &S, Module *M, DC = DC->getParent(); if (!isa<TranslationUnitDecl>(DC)) { - S.Diag(ImportLoc, diag::err_module_import_not_at_top_level_fatal) + S.Diag(ImportLoc, (FromInclude && S.isModuleVisible(M)) + ? diag::ext_module_import_not_at_top_level_noop + : diag::err_module_import_not_at_top_level_fatal) << M->getFullModuleName() << DC; S.Diag(cast<Decl>(DC)->getLocStart(), diag::note_module_import_not_at_top_level) << DC; @@ -14579,7 +14581,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation AtLoc, } void Sema::ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod) { - checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext); + checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext, true); // Determine whether we're in the #include buffer for a module. The #includes // in that buffer do not qualify as module imports; they're just an |