Namespace qualification in declarators
9.3.4 [dcl.meaning]
John Spicer

Created on 1999-08-23.00:00:00 last changed 228 months ago


Date: 2000-10-15.00:00:00

Proposed resolution (10/00):

Remove the last sentence of 9.3.4 [dcl.meaning] paragraph 1 (cited above) and the example that follows.

Date: 2000-04-15.00:00:00

Notes from 04/00 meeting:

There was some question as to whether this issue actually constituted a defect in the Standard. John Spicer suggested that machine-generated source code would be likely to run afoul of this prohibition. Francis Glassborow expressed support for a rule that would allow full qualification, or qualification relative to the namespace containing the definition, but not qualification relative to a containing namespace. There was no consensus for moving forward with a DR at this point, so the issue was left in "review" status.

Date: 2003-04-25.00:00:00

9.3.4 [dcl.meaning] paragraph 1 says:

In the qualified declarator-id for a class or namespace member definition that appears outside of the member's class or namespace, the nested-name-specifier shall not name any of the namespaces that enclose the member's definition.
This results in the following behavior:
    namespace N {
        namespace M {
            void f();
            void g();
        void M::f(){}     // okay
        void N::M::g(){}  // error
I was very surprised when this rule was pointed out to me. The change appears to have been introduced around the time of the first Santa Cruz meeting, but I don't recall discussion of it and could not find a motion related to it.

Regardless of where it came from, I also can't understand why it is there. Certainly it shouldn't matter how you name a given class or namespace.

For example, the standard permits:

    namespace N {
        namespace M {
            void f();
            void g();
        namespace X = M;
        namespace Y = N::M;
        void X::f(){}  // okay
        void Y::g(){}  // okay
So, it is okay to use an alias for N::M, but not to use N::M directly. Note that it is okay to use N::M in any other context at this point in the program (i.e., the rule is a specific restriction on declarator names, not a general rule on the use of qualified names).

Does anyone recall the intent of this rule or any rationale for its existence?

Date User Action Args
2003-04-25 00:00:00adminsetstatus: dr -> tc1
2000-11-18 00:00:00adminsetmessages: + msg445
2000-11-18 00:00:00adminsetstatus: review -> dr
2000-05-21 00:00:00adminsetmessages: + msg333
2000-05-21 00:00:00adminsetstatus: drafting -> review
2000-02-23 00:00:00adminsetstatus: open -> drafting
1999-08-23 00:00:00admincreate