This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

3926. Which namespace std is the mentioned one?

Section: 16.4.5.2.1 [namespace.std] Status: New Submitter: jim x Opened: 2023-04-19 Last modified: 2023-05-24

Priority: 4

View other active issues in [namespace.std].

View all other issues in [namespace.std].

View all issues with New status.

Discussion:

16.4.5.2.1 [namespace.std] p1 says

Unless otherwise specified, the behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std.

Which std namespace does the rule intend to refer to? Does the text refer to any namespace named std? Consider this case:

namespace A{
   namespace std{  // UB or not? 
      void show(){}
      namespace B{
         void fun(){}  // UB or not? 
     }
  }
}
int main(){  
}

A resemble usage like the above example can be seen in a libcudacxx github code, for example.

Suggested resolution:

We may want to say the namespace std only refers to the namespace whose declaration inhabits the global scope.

16.4.5.2.1 [namespace.std] p2, p7 that refers to namespace std have a similar issue.

[2023-04-24; Ville provides wording]

[2023-05-24; Reflector poll]

Set priority to 4 after reflector poll.

Proposed resolution:

This wording is relative to N4944.

  1. Modify 16.4.5.2.1 [namespace.std] as indicated:

    -?- The restrictions on the use of namespace std apply only to a top-level namespace named std. Namespaces named std nested in program-defined namespaces are not restricted this way or otherwise reserved.

    -1- Unless otherwise specified, the behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std.