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

2024-04-18


2164. Name hiding and using-directives

Section: _N4868_.6.4.10  [basic.scope.hiding]     Status: CD5     Submitter: Richard Smith     Date: 2015-07-26

[Accepted as a DR at the March, 2018 (Jacksonville) meeting.]

Consider the following example:

   const int i = -1;
   namespace T {
     namespace N { const int i = 1; }
     namespace M {
       using namespace N;
       int a[i];
     }
   }

According to 6.5.3 [basic.lookup.unqual], lookup for i finds T::N::i and stops. However, according to _N4868_.6.4.10 [basic.scope.hiding] paragraph 1, the appearance of T::N::i in namespace T does not hide ::i, so both declarations of i are visible in the declaration of a.

It seems strange that we specify this name hiding rule in two different ways in two different places, but they should at least be consistent.

On a related note, the wording in 6.5.3 [basic.lookup.unqual] paragraph 2, “as if they were declared in the nearest enclosing namespace...” could be confusing with regard to the “declared in the same scope” provisions of _N4868_.6.4.10 [basic.scope.hiding].

Proposed resolution (November, 2017)

Change _N4868_.6.4.10 [basic.scope.hiding] paragraphs 1 and 2 as follows:

A name can be hidden by an explicit declaration of that same name in a nested declarative region or derived class (6.5.2 [class.member.lookup]) A declaration of a name in a nested declarative region hides a declaration of the same name in an enclosing declarative region; see _N4868_.6.4.1 [basic.scope.declarative] and 6.5.3 [basic.lookup.unqual].

A class name (11.3 [class.name]) or enumeration name (9.7.1 [dcl.enum]) can be hidden by the name of a variable, data member, function, or enumerator declared in the same scope. If a class name (11.3 [class.name]) or enumeration name (9.7.1 [dcl.enum]) and a variable, data member, function, or enumerator are declared in the same scope declarative region (in any order) with the same name (excluding declarations made visible via using-directives (6.5.3 [basic.lookup.unqual])), the class or enumeration name is hidden wherever the variable, data member, function, or enumerator name is visible.