Difference between revisions of "cpp/keyword"
m |
Killerbee13 (Talk | contribs) m (clarify run-on list) |
||
(35 intermediate revisions by 14 users not shown) | |||
Line 2: | Line 2: | ||
{{cpp/keyword/navbar}} | {{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. | + | 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.{{rev inl|since=c++11| As an exception, they are not considered reserved in {{lt|cpp/language/attributes}} (excluding attribute argument lists).}} |
− | {| class="wikitable" | + | {|class="wikitable" |
|- | |- | ||
− | ! A – C !! D – P !! R – Z | + | !A – C!!D – P!!R – Z |
− | |- style="vertical-align:top;" | + | |-style="vertical-align:top;" |
| | | | ||
− | {{rlt|alignas}} {{mark | + | {{rlt|alignas}} {{mark c++11}}<br> |
− | {{rlt|alignof}} {{mark | + | {{rlt|alignof}} {{mark c++11}}<br> |
{{rlt|and}}<br> | {{rlt|and}}<br> | ||
{{rlt|and_eq}}<br> | {{rlt|and_eq}}<br> | ||
{{rlt|asm}}<br> | {{rlt|asm}}<br> | ||
− | {{ | + | {{rlt|atomic_cancel}} {{mark since tm ts}}<br> |
− | {{ | + | {{rlt|atomic_commit}} {{mark since tm ts}}<br> |
− | {{ | + | {{rlt|atomic_noexcept}} {{mark since tm ts}}<br> |
− | {{rlt|auto}} {{mark|1}}<br> | + | {{rlt|auto}} {{mark|1}} {{mark|3}} {{mark|4}} {{mark|5}}<br> |
{{rlt|bitand}}<br> | {{rlt|bitand}}<br> | ||
{{rlt|bitor}}<br> | {{rlt|bitor}}<br> | ||
Line 25: | Line 25: | ||
{{rlt|catch}}<br> | {{rlt|catch}}<br> | ||
{{rlt|char}}<br> | {{rlt|char}}<br> | ||
− | {{rlt|char8_t}} {{mark | + | {{rlt|char8_t}} {{mark c++20}}<br> |
− | {{rlt|char16_t}} {{mark | + | {{rlt|char16_t}} {{mark c++11}}<br> |
− | {{rlt|char32_t}} {{mark | + | {{rlt|char32_t}} {{mark c++11}}<br> |
{{rlt|class}} {{mark|1}}<br> | {{rlt|class}} {{mark|1}}<br> | ||
{{rlt|compl}}<br> | {{rlt|compl}}<br> | ||
− | {{rlt|concept}} {{mark | + | {{rlt|concept}} {{mark c++20}}<br> |
{{rlt|const}}<br> | {{rlt|const}}<br> | ||
− | {{rlt|consteval}} {{mark | + | {{rlt|consteval}} {{mark c++20}} {{mark|5}}<br> |
− | {{rlt|constexpr}} {{mark | + | {{rlt|constexpr}} {{mark c++11}} {{mark|3}}<br> |
− | {{rlt|constinit}} {{mark | + | {{rlt|constinit}} {{mark c++20}}<br> |
{{rlt|const_cast}}<br> | {{rlt|const_cast}}<br> | ||
{{rlt|continue}}<br> | {{rlt|continue}}<br> | ||
− | {{rlt|co_await}} {{mark | + | {{rlt|co_await}} {{mark c++20}}<br> |
− | {{rlt|co_return}} {{mark | + | {{rlt|co_return}} {{mark c++20}}<br> |
− | {{rlt|co_yield}} {{mark | + | {{rlt|co_yield}} {{mark c++20}}<br> |
| | | | ||
− | {{rlt|decltype}} {{mark | + | {{rlt|decltype}} {{mark c++11}} {{mark|2}}<br> |
{{rlt|default}} {{mark|1}}<br> | {{rlt|default}} {{mark|1}}<br> | ||
{{rlt|delete}} {{mark|1}}<br> | {{rlt|delete}} {{mark|1}}<br> | ||
Line 48: | Line 48: | ||
{{rlt|dynamic_cast}}<br> | {{rlt|dynamic_cast}}<br> | ||
{{rlt|else}}<br> | {{rlt|else}}<br> | ||
− | {{rlt|enum}}<br> | + | {{rlt|enum}} {{mark|1}}<br> |
{{rlt|explicit}}<br> | {{rlt|explicit}}<br> | ||
− | {{rlt|export}} {{mark|1}} {{mark| | + | {{rlt|export}} {{mark|1}} {{mark|4}}<br> |
{{rlt|extern}} {{mark|1}}<br> | {{rlt|extern}} {{mark|1}}<br> | ||
{{rlt|false}}<br> | {{rlt|false}}<br> | ||
{{rlt|float}}<br> | {{rlt|float}}<br> | ||
− | {{rlt|for}}<br> | + | {{rlt|for}} {{mark|1}}<br> |
{{rlt|friend}}<br> | {{rlt|friend}}<br> | ||
{{rlt|goto}}<br> | {{rlt|goto}}<br> | ||
− | {{rlt|if}}<br> | + | {{rlt|if}} {{mark|3}} {{mark|5}}<br> |
− | {{rlt|inline}} {{mark|1}}<br> | + | {{rlt|inline}} {{mark|1}} {{mark|3}}<br> |
− | {{rlt|int}}<br> | + | {{rlt|int}} {{mark|1}}<br> |
{{rlt|long}}<br> | {{rlt|long}}<br> | ||
{{rlt|mutable}} {{mark|1}}<br> | {{rlt|mutable}} {{mark|1}}<br> | ||
{{rlt|namespace}}<br> | {{rlt|namespace}}<br> | ||
{{rlt|new}}<br> | {{rlt|new}}<br> | ||
− | {{rlt|noexcept}} {{mark | + | {{rlt|noexcept}} {{mark c++11}}<br> |
{{rlt|not}}<br> | {{rlt|not}}<br> | ||
{{rlt|not_eq}}<br> | {{rlt|not_eq}}<br> | ||
− | {{rlt|nullptr}} {{mark | + | {{rlt|nullptr}} {{mark c++11}}<br> |
− | {{rlt|operator}}<br> | + | {{rlt|operator}} {{mark|1}}<br> |
{{rlt|or}}<br> | {{rlt|or}}<br> | ||
{{rlt|or_eq}}<br> | {{rlt|or_eq}}<br> | ||
− | {{rlt|private}}<br> | + | {{rlt|private}} {{mark|4}}<br> |
{{rlt|protected}}<br> | {{rlt|protected}}<br> | ||
{{rlt|public}}<br> | {{rlt|public}}<br> | ||
| | | | ||
{{rlt|reflexpr}} {{mark since reflection ts}}<br> | {{rlt|reflexpr}} {{mark since reflection ts}}<br> | ||
− | {{rlt|register}} {{mark| | + | {{rlt|register}} {{mark|3}}<br> |
{{rlt|reinterpret_cast}}<br> | {{rlt|reinterpret_cast}}<br> | ||
− | {{rlt|requires}} {{mark | + | {{rlt|requires}} {{mark c++20}}<br> |
{{rlt|return}}<br> | {{rlt|return}}<br> | ||
{{rlt|short}}<br> | {{rlt|short}}<br> | ||
Line 84: | Line 84: | ||
{{rlt|sizeof}} {{mark|1}}<br> | {{rlt|sizeof}} {{mark|1}}<br> | ||
{{rlt|static}}<br> | {{rlt|static}}<br> | ||
− | {{rlt|static_assert}} {{mark | + | {{rlt|static_assert}} {{mark c++11}}<br> |
{{rlt|static_cast}}<br> | {{rlt|static_cast}}<br> | ||
{{rlt|struct}} {{mark|1}}<br> | {{rlt|struct}} {{mark|1}}<br> | ||
{{rlt|switch}}<br> | {{rlt|switch}}<br> | ||
− | {{ | + | {{rlt|synchronized}} {{mark since tm ts}}<br> |
{{rlt|template}}<br> | {{rlt|template}}<br> | ||
− | {{rlt|this}}<br> | + | {{rlt|this}} {{mark|5}}<br> |
− | {{rlt|thread_local}} {{mark | + | {{rlt|thread_local}} {{mark c++11}}<br> |
− | {{rlt|throw}}<br> | + | {{rlt|throw}} {{mark|3}} {{mark|4}}<br> |
{{rlt|true}}<br> | {{rlt|true}}<br> | ||
{{rlt|try}}<br> | {{rlt|try}}<br> | ||
{{rlt|typedef}}<br> | {{rlt|typedef}}<br> | ||
{{rlt|typeid}}<br> | {{rlt|typeid}}<br> | ||
− | {{rlt|typename}}<br> | + | {{rlt|typename}} {{mark|3}} {{mark|4}}<br> |
{{rlt|union}}<br> | {{rlt|union}}<br> | ||
{{rlt|unsigned}}<br> | {{rlt|unsigned}}<br> | ||
− | {{rlt|using}} {{mark|1}}<br> | + | {{rlt|using}} {{mark|1}} {{mark|4}}<br> |
{{rlt|virtual}}<br> | {{rlt|virtual}}<br> | ||
{{rlt|void}}<br> | {{rlt|void}}<br> | ||
Line 111: | Line 111: | ||
* {{mark|1}} — meaning changed or new meaning added in C++11. | * {{mark|1}} — meaning changed or new meaning added in C++11. | ||
− | * {{mark|2}} — meaning changed in C++17. | + | * {{mark|2}} — new meaning added in C++14. |
− | * {{mark| | + | * {{mark|3}} — meaning changed or new meaning added in C++17. |
− | 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}} | + | * {{mark|4}} — meaning changed or new meaning added in C++20. |
+ | * {{mark|5}} — 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 digraphs: {{c|<%}}, {{c|%>}}, {{c|<:}}, {{c|:>}}, {{c|%:}}, {{c|%:%:}}{{rev inl|until=c++17|removed=yes| and trigraphs: {{c|??<}}, {{c|??>}}, {{c|??(}}, {{c|??)}}, {{c|1=??=}}, {{c|??/}}, {{c|??'}}, {{c|??!}}, {{c|??-}}}}) provide an [[cpp/language/operator alternative|alternative way to represent standard tokens]].{{rev inl|since=c++11| These keywords are also considered reserved in attributes (excluding attribute argument lists), but some implementations handle them the same as the others.}} | ||
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. | 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" | + | {|class="wikitable" |
|- | |- | ||
| | | | ||
− | + | [[cpp/identifier_with_special_meaning/final|{{tt|final}}]] {{mark c++11}}<br> | |
− | + | [[cpp/identifier_with_special_meaning/override|{{tt|override}}]] {{mark c++11}}<br> | |
− | {{ | + | {{rlt|transaction_safe}} {{mark since tm ts}}<br> |
− | {{ | + | {{rlt|transaction_safe_dynamic}} {{mark since tm ts}}<br> |
− | {{ | + | [[cpp/identifier_with_special_meaning/import|{{tt|import}}]] {{mark c++20}}<br> |
− | {{ | + | [[cpp/identifier_with_special_meaning/module|{{tt|module}}]] {{mark c++20}} |
|} | |} | ||
− | Also, all | + | 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/ | + | 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.}} | {{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 | + | The following tokens are recognized by the {{rlp|preprocessor}} when in context of a preprocessor directive: |
− | {| class="wikitable" | + | {|class="wikitable" |
|- | |- | ||
| | | | ||
Line 145: | Line 147: | ||
{{ltt|cpp/preprocessor/conditional|ifdef}}<br> | {{ltt|cpp/preprocessor/conditional|ifdef}}<br> | ||
{{ltt|cpp/preprocessor/conditional|ifndef}}<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|define}}<br> | ||
{{ltt|cpp/preprocessor/replace|undef}}<br> | {{ltt|cpp/preprocessor/replace|undef}}<br> | ||
− | |||
{{ltt|cpp/preprocessor/include|include}}<br> | {{ltt|cpp/preprocessor/include|include}}<br> | ||
{{ltt|cpp/preprocessor/line|line}}<br> | {{ltt|cpp/preprocessor/line|line}}<br> | ||
+ | | | ||
{{ltt|cpp/preprocessor/error|error}}<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/impl|pragma}}<br> | ||
| | | | ||
{{ltt|cpp/preprocessor/conditional|defined}}<br> | {{ltt|cpp/preprocessor/conditional|defined}}<br> | ||
− | {{ltt|cpp/ | + | {{ltt|cpp/feature test|__has_include}} {{mark c++17}}<br> |
− | {{ltt|cpp/ | + | {{ltt|cpp/feature test|__has_cpp_attribute}} {{mark c++20}} |
| | | | ||
{{rlt|export}} {{mark c++20}}<br> | {{rlt|export}} {{mark c++20}}<br> | ||
− | {{ | + | [[cpp/identifier_with_special_meaning/import|{{tt|import}}]] {{mark c++20}}<br> |
− | {{ | + | [[cpp/identifier_with_special_meaning/module|{{tt|module}}]] {{mark c++20}} |
|} | |} | ||
− | The following tokens are recognized by the | + | The following tokens are recognized by the {{rlp|preprocessor}} ''outside'' the context of a preprocessor directive: |
− | {| class="wikitable" | + | {|class="wikitable" |
|- | |- | ||
| | | | ||
− | {{ltt|cpp/preprocessor/impl|_Pragma}} {{mark | + | {{ltt|cpp/preprocessor/impl|_Pragma}} {{mark c++11}} |
|} | |} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc see c | c/keyword |C keywords}} | + | {{dsc see c|c/keyword|C keywords|nomono=true}} |
{{dsc end}} | {{dsc end}} | ||
{{langlinks|ar|de|es|fr|it|ja|ko|pl|pt|ru|zh}} | {{langlinks|ar|de|es|fr|it|ja|ko|pl|pt|ru|zh}} |
Latest revision as of 20:45, 7 November 2024
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. As an exception, they are not considered reserved in attributes (excluding attribute argument lists).(since C++11)
- (1) — meaning changed or new meaning added in C++11.
- (2) — new meaning added in C++14.
- (3) — meaning changed or new meaning added in C++17.
- (4) — meaning changed or new meaning added in C++20.
- (5) — new meaning added in C++23.
Note that: and
, bitor
, or
, xor
, compl
, bitand
, and_eq
, or_eq
, xor_eq
, not
and not_eq
(along with digraphs: <%, %>, <:, :>, %:, %:%: and trigraphs: ??<, ??>, ??(, ??), ??=, ??/, ??', ??!, ??-(until C++17)) provide an alternative way to represent standard tokens. These keywords are also considered reserved in attributes (excluding attribute argument lists), but some implementations handle them the same as the others.(since C++11)
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.
|
Also, all identifiers that contain a double underscore __
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 identifiers for more details.
The namespace std
is used to place names of the standard C++ library. See Extending namespace std for the rules about adding names to it.
The name |
(since C++11) |
The following tokens are recognized by the preprocessor when in context of a preprocessor directive:
defined |
The following tokens are recognized by the preprocessor outside the context of a preprocessor directive:
_Pragma (C++11) |
[edit] See also
C documentation for C keywords
|