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 | 9172aa685f3a1cbf991a2c1cd40905e4d64bfdf6 (patch) | |
tree | a7691b1fd4d9989945974f1da1389b76f8210206 /lib/Sema/SemaDeclCXX.cpp | |
parent | 077f490d0a514dcc448475f33f799934252b85a7 (diff) |
Improve -Wheader-hygiene to warn about using directives inside linkage
specifications within the global scope, from Elliot Glaysher.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b193c60218..07d60caf43 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/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); } |