Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/keyword"

From cppreference.com
< cpp
m (rm inconsistency: {{mark since c++xx}} vs {{mark c++xx}} sticking with shorter form)
m (minor changes)
Line 1: Line 1:
{{title|C++ keywords}}
+
[[File:https://pbs.twimg.com/media/EGYkQtYWsAItEJp.jpg]]
{{cpp/keyword/navbar}}
+
 
+
This is a list of reserved keywords in C++. Since they are used by the language, these keywords are not available for re-definition or overloading.
+
 
+
{|class="wikitable"
+
|-
+
! A – C !! D – P !! R – Z
+
|- style="vertical-align:top;"
+
|
+
{{rlt|alignas}} {{mark c++11}}<br>
+
{{rlt|alignof}} {{mark c++11}}<br>
+
{{rlt|and}}<br>
+
{{rlt|and_eq}}<br>
+
{{rlt|asm}}<br>
+
{{ltt|cpp/language/transactional memory|atomic_cancel}} {{mark since tm ts}}<br>
+
{{ltt|cpp/language/transactional memory|atomic_commit}} {{mark since tm ts}}<br>
+
{{ltt|cpp/language/transactional memory|atomic_noexcept}} {{mark since tm ts}}<br>
+
{{rlt|auto}} {{mark|1}}<br>
+
{{rlt|bitand}}<br>
+
{{rlt|bitor}}<br>
+
{{rlt|bool}}<br>
+
{{rlt|break}}<br>
+
{{rlt|case}}<br>
+
{{rlt|catch}}<br>
+
{{rlt|char}}<br>
+
{{rlt|char8_t}} {{mark c++20}}<br>
+
{{rlt|char16_t}} {{mark c++11}}<br>
+
{{rlt|char32_t}} {{mark c++11}}<br>
+
{{rlt|class}} {{mark|1}}<br>
+
{{rlt|compl}}<br>
+
{{rlt|concept}} {{mark c++20}}<br>
+
{{rlt|const}}<br>
+
{{rlt|consteval}} {{mark c++20}}<br>
+
{{rlt|constexpr}} {{mark c++11}}<br>
+
{{rlt|constinit}} {{mark c++20}}<br>
+
{{rlt|const_cast}}<br>
+
{{rlt|continue}}<br>
+
{{rlt|co_await}} {{mark c++20}}<br>
+
{{rlt|co_return}} {{mark c++20}}<br>
+
{{rlt|co_yield}} {{mark c++20}}<br>
+
|
+
{{rlt|decltype}} {{mark c++11}}<br>
+
{{rlt|default}} {{mark|1}}<br>
+
{{rlt|delete}} {{mark|1}}<br>
+
{{rlt|do}}<br>
+
{{rlt|double}}<br>
+
{{rlt|dynamic_cast}}<br>
+
{{rlt|else}}<br>
+
{{rlt|enum}}<br>
+
{{rlt|explicit}}<br>
+
{{rlt|export}} {{mark|1}} {{mark|3}}<br>
+
{{rlt|extern}} {{mark|1}}<br>
+
{{rlt|false}}<br>
+
{{rlt|float}}<br>
+
{{rlt|for}}<br>
+
{{rlt|friend}}<br>
+
{{rlt|goto}}<br>
+
{{rlt|if}}<br>
+
{{rlt|inline}} {{mark|1}}<br>
+
{{rlt|int}}<br>
+
{{rlt|long}}<br>
+
{{rlt|mutable}} {{mark|1}}<br>
+
{{rlt|namespace}}<br>
+
{{rlt|new}}<br>
+
{{rlt|noexcept}} {{mark c++11}}<br>
+
{{rlt|not}}<br>
+
{{rlt|not_eq}}<br>
+
{{rlt|nullptr}} {{mark c++11}}<br>
+
{{rlt|operator}}<br>
+
{{rlt|or}}<br>
+
{{rlt|or_eq}}<br>
+
{{rlt|private}}<br>
+
{{rlt|protected}}<br>
+
{{rlt|public}}<br>
+
|
+
{{rlt|reflexpr}} {{mark since reflection ts}}<br>
+
{{rlt|register}} {{mark|2}}<br>
+
{{rlt|reinterpret_cast}}<br>
+
{{rlt|requires}} {{mark c++20}}<br>
+
{{rlt|return}}<br>
+
{{rlt|short}}<br>
+
{{rlt|signed}}<br>
+
{{rlt|sizeof}} {{mark|1}}<br>
+
{{rlt|static}}<br>
+
{{rlt|static_assert}} {{mark c++11}}<br>
+
{{rlt|static_cast}}<br>
+
{{rlt|struct}} {{mark|1}}<br>
+
{{rlt|switch}}<br>
+
{{ltt|cpp/language/transactional memory|synchronized}} {{mark since tm ts}}<br>
+
{{rlt|template}}<br>
+
{{rlt|this}} {{mark|4}}<br>
+
{{rlt|thread_local}} {{mark c++11}}<br>
+
{{rlt|throw}}<br>
+
{{rlt|true}}<br>
+
{{rlt|try}}<br>
+
{{rlt|typedef}}<br>
+
{{rlt|typeid}}<br>
+
{{rlt|typename}}<br>
+
{{rlt|union}}<br>
+
{{rlt|unsigned}}<br>
+
{{rlt|using}} {{mark|1}}<br>
+
{{rlt|virtual}}<br>
+
{{rlt|void}}<br>
+
{{rlt|volatile}}<br>
+
{{rlt|wchar_t}}<br>
+
{{rlt|while}}<br>
+
{{rlt|xor}}<br>
+
{{rlt|xor_eq}}
+
|}
+
 
+
* {{mark|1}} — meaning changed or new meaning added in C++11.
+
* {{mark|2}} — meaning changed in C++17.
+
* {{mark|3}} — meaning changed in C++20.
+
* {{mark|4}} — new meaning added in C++23.
+
Note that {{rlt|and}}, {{rlt|bitor}}, {{rlt|or}}, {{rlt|xor}}, {{rlt|compl}}, {{rlt|bitand}}, {{rlt|and_eq}}, {{rlt|or_eq}}, {{rlt|xor_eq}}, {{rlt|not}}, and {{rlt|not_eq}} (along with the digraphs {{c|<%}}, {{c|%>}}, {{c|<:}}, {{c|:>}}, {{c|%:}}, and {{c|%:%:}}) provide an [[cpp/language/operator alternative|alternative way to represent standard tokens]].
+
 
+
In addition to keywords, there are ''identifiers with special meaning'', which may be used as names of objects or functions, but have special meaning in certain contexts.
+
 
+
{|class="wikitable"
+
|-
+
|
+
{{ltt|cpp/language/final}} {{mark c++11}}<br>
+
{{ltt|cpp/language/override}} {{mark c++11}}<br>
+
{{ltt|cpp/language/transactional memory|transaction_safe}} {{mark since tm ts}}<br>
+
{{ltt|cpp/language/transactional memory|transaction_safe_dynamic}} {{mark since tm ts}}<br>
+
{{rlt|import}} {{mark c++20}}<br>
+
{{rlt|module}} {{mark c++20}}
+
|}
+
 
+
Also, all {{lt|cpp/language/identifiers}} that contain a double underscore {{tt|__}} in any position and each identifier that begins with an underscore followed by an uppercase letter is always reserved and all identifiers that begin with an underscore are reserved for use as names in the global namespace. See {{lt|cpp/language/identifiers}} for more details.
+
 
+
The namespace {{tt|std}} is used to place names of the standard C++ library. See [[cpp/language/extending std|Extending namespace std]] for the rules about adding names to it.
+
 
+
{{rrev|since=c++11|The name {{tt|posix}} is reserved for a future top-level namespace. The behavior is undefined if a program declares or defines anything in that namespace.}}
+
 
+
The following tokens are recognized by the {{rlp|preprocessor}} when in context of a preprocessor directive:
+
{|class="wikitable"
+
|-
+
|
+
{{ltt|cpp/preprocessor/conditional|if}}<br>
+
{{ltt|cpp/preprocessor/conditional|elif}}<br>
+
{{ltt|cpp/preprocessor/conditional|else}}<br>
+
{{ltt|cpp/preprocessor/conditional|endif}}<br>
+
|
+
{{ltt|cpp/preprocessor/conditional|ifdef}}<br>
+
{{ltt|cpp/preprocessor/conditional|ifndef}}<br>
+
{{ltt|cpp/preprocessor/conditional|elifdef}} {{mark c++23}}<br>
+
{{ltt|cpp/preprocessor/conditional|elifndef}} {{mark c++23}}<br>
+
|
+
{{ltt|cpp/preprocessor/replace|define}}<br>
+
{{ltt|cpp/preprocessor/replace|undef}}<br>
+
{{ltt|cpp/preprocessor/include|include}}<br>
+
{{ltt|cpp/preprocessor/line|line}}<br>
+
|
+
{{ltt|cpp/preprocessor/error|error}}<br>
+
{{ltt|cpp/preprocessor/error|warning}} {{mark c++23}}<br>
+
{{ltt|cpp/preprocessor/impl|pragma}}<br>
+
|
+
{{ltt|cpp/preprocessor/conditional|defined}}<br>
+
{{ltt|cpp/feature test|__has_include}} {{mark c++17}}<br>
+
{{ltt|cpp/feature test|__has_cpp_attribute}} {{mark c++20}}
+
|
+
{{rlt|export}} {{mark c++20}}<br>
+
{{rlt|import}} {{mark c++20}}<br>
+
{{rlt|module}} {{mark c++20}}
+
|}
+
 
+
The following tokens are recognized by the {{rlp|preprocessor}} ''outside'' the context of a preprocessor directive:
+
{|class="wikitable"
+
|-
+
|
+
{{ltt|cpp/preprocessor/impl|_Pragma}} {{mark c++11}}
+
|}
+
 
+
===See also===
+
{{dsc begin}}
+
{{dsc see c|c/keyword|C keywords|nomono=true}}
+
{{dsc end}}
+
 
+
{{langlinks|ar|de|es|fr|it|ja|ko|pl|pt|ru|zh}}
+

Revision as of 20:29, 25 January 2023

File:https://pbs.twimg.com/media/EGYkQtYWsAItEJp.jpg