Arising from my answer to Dynamic array of objects in C++ and as a follow up to What are the rules about using an underscore in a C++ identifier?:
apparently, names beginning with _
followed by an uppercase letter are reserved in the global namespace.
17.4.3.2.1 Global names [
lib.global.names
]Certain sets of names and function signatures are always reserved to the implementation:
- Each name that contains a double underscore (
__
) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use.- Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.165
165) Such names are also reserved in namespace
::std
(17.4.3.1).
In my answer to the first question I had a class that looked like this
class A
{
private:
vector<int> _Ints;
}
In the comments I was told the _Ints
identifier invokes undefined behavior, since it is a reserved name. However, according to the recent draft of the standard, name look-up of a member variable occurs using the following rule:
3.4.3.1 Class members [
class.qual
]If the nested-name-specifier of a qualified-id nominates a class, the name specified after the nested-namespecifier is looked up in the scope of the class (10.2), except for the cases listed below. The name shall represent one or more members of that class or of one of its base classes
To me, that means that no member variable can ever be part of the global namespace, as its scope is the class.
And now, the question:
Is my understanding correct that member variables will never violate the implementation reserved names rule since they are not in the global namespace? If I am not correct, could someone explain my misunderstanding of the look-up rule?