From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20054 invoked by alias); 29 Apr 2002 20:28:16 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 20027 invoked from network); 29 Apr 2002 20:28:12 -0000 Received: from unknown (HELO zwingli.cygnus.com) (208.245.165.35) by sources.redhat.com with SMTP; 29 Apr 2002 20:28:12 -0000 Received: by zwingli.cygnus.com (Postfix, from userid 442) id 6452B5EA11; Mon, 29 Apr 2002 15:28:11 -0500 (EST) To: Don Howard Cc: Subject: Re: C++ namespace using directives References: From: Jim Blandy Date: Mon, 29 Apr 2002 13:28:00 -0000 In-Reply-To: Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-04/txt/msg00493.txt.bz2 Don Howard writes: > On Tue, 16 Apr 2002, Jim Blandy wrote: > > Could a C++ person check my understanding of `using namespace' > > directives? > > > > I'm reading Stroustrup, and the more I read about `using namespace', > > the weirder it gets. Check this out: > > > > namespace A > > { > > int x; > > int y; > > int z; > > }; > > > > void f () > > { > > int *x; > > > > { > > int *y; > > using namespace A; > > > > *x; /* `x' refers to local x, not A::x */ > > *y; /* `y` refers to local y, not A::y */ > > z; /* `z' refers to A::z */ > > } > > } > > This example seems correct to me, as the compiler can dis-ambiguate based > on type-- dereference works on pointers, so x and y must refer to the > local versions. No, that's not what's going on at all. In Stroustrup's example, there is no dereferencing going on, and he makes the same claims about which binding each reference refers to as I do. I added the dereferences as a sanity check, to make sure GCC was doing the right thing. So you see why I think this behavior is way wacky? The `using namespace' directive appears in the inner block, the local definition appears in the outer block, but references to `x' in the inner block still see the local definition in the outer block.