Title
Name hiding and using-directives
Status
cd5
Section
_N4868_.6.4.10 [basic.scope.hiding]
Submitter
Richard Smith

Created on 2015-07-26.00:00:00 last changed 2 months ago

Messages

Date: 2017-11-15.00:00:00

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.

Date: 2018-03-15.00:00:00

[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].

History
Date User Action Args
2020-12-15 00:00:00adminsetstatus: dr -> cd5
2018-04-11 00:00:00adminsetstatus: tentatively ready -> dr
2018-02-27 00:00:00adminsetmessages: + msg5851
2018-02-27 00:00:00adminsetstatus: drafting -> tentatively ready
2015-07-26 00:00:00admincreate