This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-05-06


311. Using qualified name to reopen nested namespace

Section: 9.8.2  [namespace.def]     Status: NAD     Submitter: Bjarne Stroustrup     Date: 18 Sep 2001

I received an inquiry/complaint that you cannot re-open a namespace using a qualified name. For example, the following program is ok, but if you uncomment the commented lines you get an error:

namespace A {
    namespace N {
	int a;
    }
    int b;
    namespace M {
	int c;
    }
}

//namespace A::N {
//    int d;
//}

namespace A {
    namespace M {
        int e;
    }
}

int main()
{
    A::N::a = 1;
    A::b = 2;
    A::M::c = 3;
//  A::N::d = 4;
    A::M::e = 5;
}

Andrew Koenig: There's a name lookup issue lurking here. For example:

    int x;

    namespace A {
	int x;
	namespace N {
	   int y;
	};
    }

    namespace A::N {
        int* y = &x;  // which x?
    }

Jonathan Caves: I would assume that any rule would state that:

namespace A::B {
would be equivalent to:
namespace A {
   namespace B {
so in your example 'x' would resolve to A::x

BTW: we have received lots of bug reports about this "oversight".

Lawrence Crowl: Even worse is

    int x;
    namespace A {
      int x;
    }
    namespace B {
      int x;
      namespace ::A {
         int* y = &x;
      }
    }
I really don't think that the benefits of qualified names here is worth the cost.

Notes from April 2003 meeting:

We're closing this because it's on the Evolution working group list.