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

Sebastian Redl wasti.redl at gmx.at
Fri Mar 25 06:34:30 PDT 2011


-------- Original-Nachricht --------
> Datum: Wed, 23 Mar 2011 12:22:11 -0700
> Von: "Elliot Glaysher (Chromium)" <erg at chromium.org>
> An: Douglas Gregor <dgregor at apple.com>
> CC: Sebastian Redl <sebastian.redl at getdesigned.at>, "cfe-dev at cs.uiuc.edu" <cfe-dev at cs.uiuc.edu>, "cfe-commits at cs.uiuc.edu" <cfe-commits at cs.uiuc.edu>, Daniel James <dnljms at gmail.com>
> Betreff: Re: [cfe-commits] [PATCH] Re: [cfe-dev] Interest in a -Wusing-namespace-in-headers?

> On Sat, Mar 19, 2011 at 3:55 PM, Douglas Gregor <dgregor at apple.com> wrote:
> > On Mar 19, 2011, at 3:27 AM, Sebastian Redl
> <sebastian.redl at getdesigned.at> wrote:
> >> Do we want to warn about this?
> >>
> >> extern "C++" {
> >>  using namespace foo;
> >> }
> >>
> >> Because the fact that extern blocks are decl contexts has bitten me
> before, and the above suggestion would fall prey to the same issue.
> >
> > Good point! Yes, we do want to warn about that.
> 
> Is the attached patch sufficient, or are there other cases I should be
> checking for?

That's not the right way to do it, since now you would warn about this:

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.

Sebastian
-- 
NEU: FreePhone - kostenlos mobil telefonieren und surfen!			
Jetzt informieren: http://www.gmx.net/de/go/freephone



More information about the cfe-commits mailing list