cpp/language/identifiers

An identifier is an arbitrarily long sequence of digits, underscores, lowercase and uppercase Latin letters, and most Unicode characters.

The first character of a valid identifier must be one of the following:
 * uppercase latin letters A-Z
 * lowercase latin letters a-z
 * underscore
 * any Unicode character with the Unicode property XID_Start

Any other character of a valid identifier must be one of the following:
 * digits 0-9
 * uppercase latin letters A-Z
 * lowercase latin letters a-z
 * underscore
 * any Unicode character with the Unicode property XID_Continue

The lists of characters with properties XID_Start and XID_Continue can be found in DerivedCoreProperties.txt.

Identifiers are case-sensitive (lowercase and uppercase letters are distinct), and every character is significant. Every identifier must conform to Normalization Form C.

Note: Support of Unicode identifiers is limited in most implementations, e.g. gcc (until 10).

In declarations
An identifier can be used objects, references, functions, enumerators, types, class members, namespaces, templates, template specializations, goto labels, and other entities, with the following exceptions:
 * the identifiers that are keywords cannot be used for other purposes;


 * the identifiers that are for certain operators and punctuators cannot be used for other purposes;


 * Identifiers of one of the following forms are reserved:
 * identifiers with a double underscore anywhere;
 * identifiers that begin with an underscore followed by an uppercase letter;
 * in the global namespace, identifiers that begin with an underscore.

"Reserved" here means that the standard library headers or declare such identifiers for their internal needs, the compiler may predefine non-standard identifiers of that kind, and that name mangling algorithm may assume that some of these identifiers are not in use. If the programmer uses such identifiers, the program is ill-formed, no diagnostic required.

In addition, it's undefined behavior to or  certain names in a translation unit, see reserved macro names for more details.

Zombie identifiers
As of C++14, some identifiers are removed from the C++ standard library. They are listed in the list of zombie names.

However, these identifiers are still reserved for previous standardization in a certain context. Removed member function names may not be used as a name for function-like macros, and other removed member names may not be used as a name for object-like macros in portable code.

In expressions
An identifier that names a variable, a function, or an enumerator can be used as an. The result of an expression consisting of just the identifier is the entity named by the identifier. The of the expression is lvalue if the identifier names a function, a variable, or a data member, and  otherwise (e.g. an  is  expression). The type of the expression is determined as follows:


 * Otherwise, the type of the expression is the same as the type of the entity named.

Within the body of a non-static, each identifier that names a non-static member is implicitly transformed to a class member access expression.

Unqualified identifiers
Besides suitably declared identifiers, the following can be used in expressions in the same role:
 * an name in function notation, such as  or ;
 * a name, such as ;


 * a name followed by its argument list, such as ;
 * the character followed by a class name, such as ;

Together with identifiers they are known as unqualified id-expressions.

Qualified identifiers
A qualified id-expression is an unqualified id-expression prepended by a scope resolution operator, and optionally, a sequence of any of the following separated by scope resolution operators:
 * a namespace name;
 * a class name;

For example, the expression is an expression that names the static member  in the class  in namespace. The expression names the function  in the global namespace. The expression names the global variable  in namespace, which is a top-level namespace. The expression names the type  declared in namespace, which is declared in namespace.

The keyword may appear in qualified identifiers as necessary to disambiguate.

See for the details of the name lookup for qualified identifiers.

Names
A name is the use of one of the following to refer to an entity:
 * an identifier;
 * an overloaded operator name in function notation ;
 * a user-defined conversion function name ;


 * a template name followed by its argument list.

Every name is introduced into the program by a. A name used in more than one translation unit may refer to the same or different entities, depending on.

When the compiler encounters an unknown name in a program, it associates it with the declaration that introduced the name by means of, except for the s in template declarations and definitions (for those names, the compiler determines whether they name a type, a template, or some other entity, which may require ).