diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-03-26 22:25:30 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-03-26 22:25:30 +0000 |
| commit | a172e088244e543ddcd5d8e79d848d6711e900a6 (patch) | |
| tree | 2ca02d0fcf09b01f586f6f1930ce08a008111139 /clang/lib | |
| parent | e4663456752ff6160c0817afb732b83b7ef62cc2 (diff) | |
| download | bcm5719-llvm-a172e088244e543ddcd5d8e79d848d6711e900a6.tar.gz bcm5719-llvm-a172e088244e543ddcd5d8e79d848d6711e900a6.zip | |
Improve -Wheader-hygiene to warn about using directives inside linkage
specifications within the global scope, from Elliot Glaysher.
llvm-svn: 128352
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index b193c602184..07d60caf435 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -3817,6 +3817,19 @@ NamespaceDecl *Sema::getOrCreateStdNamespace() { return getStdNamespace(); } +/// \brief Determine whether a using statement is in a context where it will be +/// apply in all contexts. +static bool IsUsingDirectiveInToplevelContext(DeclContext *CurContext) { + switch (CurContext->getDeclKind()) { + case Decl::TranslationUnit: + return true; + case Decl::LinkageSpec: + return IsUsingDirectiveInToplevelContext(CurContext->getParent()); + default: + return false; + } +} + Decl *Sema::ActOnUsingDirective(Scope *S, SourceLocation UsingLoc, SourceLocation NamespcLoc, @@ -3902,7 +3915,7 @@ Decl *Sema::ActOnUsingDirective(Scope *S, SS.getWithLocInContext(Context), IdentLoc, Named, CommonAncestor); - if (CurContext->getDeclKind() == Decl::TranslationUnit && + if (IsUsingDirectiveInToplevelContext(CurContext) && !SourceMgr.isFromMainFile(IdentLoc)) { Diag(IdentLoc, diag::warn_using_directive_in_header); } |

