[cfe-commits] [PATCH] Re: [cfe-dev] Interest in a -Wusing-namespace-in-headers?

Peter Collingbourne peter at pcc.me.uk
Fri Mar 25 09:40:30 PDT 2011


On Fri, Mar 25, 2011 at 02:34:30PM +0100, Sebastian Redl wrote:
> namespace ns1 {
>   extern "C++" {
>     using namespace ns2;
>   }
> }
> 
> What you have to do is call DeclContext::getEnclosingNamespaceContext() on the context that contains the using directive, and check whether that is a TranslationUnitDecl or a NamespaceDecl.

I don't think that's right either, as now you would warn on this:

void foo() {
  using namespace ns2;
}

I believe the correct thing to do is to iterate through
declaration context parents until you reach something that is not a
LinkageSpecDecl, and warn if it is a TranslationUnitDecl.

Thanks,
-- 
Peter



More information about the cfe-commits mailing list