Is there a way to use a keyword as identifier in an enum?

As per 2.12 [lex.key] in the C++14 standard, certain identifiers must never be used as identifiers:

The identifiers shown in Table 4 are reserved for use as keywords (that is, they are unconditionally treated as keywords in phase 7) except in an attribute token (7.6.1) [ Note: The export keyword is unused but is reserved for future use. — end note ]:

Table 4 — Keywords

   alignas continue friend register true
   alignof decltype goto reinterpret_cast try
   asm default if return typedef
   auto delete inline short typeid
   bool do int signed typename
   break double long sizeof union
   case dynamic_cast mutable static unsigned
   catch else namespace static_assert using
   char enum new static_cast virtual
   char16_t explicit noexcept struct void
   char32_t export nullptr switch volatile
   class extern operator template wchar_t
   const false private this while
   constexpr float protected thread_local
   const_cast for public throw

Furthermore, some identifiers shall not be used:

Furthermore, the alternative representations shown in Table 5 for certain operators and punctuators (2.6) are reserved and shall not be used otherwise:

Table 5 — Alternative representations

and and_eq bitand bitor compl not
not_eq or or_eq xor xor_eq

Even furthermore, as per 2.11 Identifier [lex.name], some are illegal to use, but the compiler is not required to tell you:

some identifiers are reserved for use by C++ implementations and standard libraries (17.6.4.3.2) and shall not be used otherwise; no diagnostic is required

— Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.12) 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.


No they cant be used.

From MSDN

Keywords are predefined reserved identifiers that have special meanings. They cannot be used as identifiers in your program.

The rule for identifier says:

An identifier can be used to name objects, references, functions, enumerators, types, class members, namespaces, templates, template specializations, parameter packs, goto labels, and other entities, with the following exceptions:

  • the identifiers that are keywords cannot be used for other purposes;
  • the identifiers with a double underscore anywhere are reserved;
  • the identifiers that begin with an underscore followed by an uppercase letter are reserved;
  • the identifiers that begin with an underscore are reserved in the global namespace.

Tags:

C++

Enums

Keyword