C++ attribute: deprecated (since C++14)
From cppreference.com
< cpp | language | attributes
Indicates that the name or entity declared with this attribute is deprecated, that is, the use is allowed, but discouraged for some reason.
Syntax
[[deprecated ]]
|
(1) | ||||||||
[[deprecated( string-literal )]]
|
(2) | ||||||||
string-literal | - | text that could be used to explain the rationale for deprecation and/or to suggest a replacing entity |
Explanation
Indicates that the use of the name or entity declared with this attribute is allowed, but discouraged for some reason. Compilers typically issue warnings on such uses. The string-literal, if specified, is usually included in the warnings.
This attribute is allowed in declarations of the following names or entities:
- class/struct/union: struct [[deprecated]] S;,
- typedef-name, including those declared by alias declaration: [[deprecated]] typedef S* PS;, using PS [[deprecated]] = S*;,
- variable, including static data member: [[deprecated]] int x;,
- non-static data member: union U { [[deprecated]] int n; };,
- function: [[deprecated]] void f();,
- namespace: namespace [[deprecated]] NS { int x; }
- enumeration: enum [[deprecated]] E {};,
- enumerator: enum { A [[deprecated]], B [[deprecated]] = 42 };.
- template specialization: template<> struct [[deprecated]] X<int> {};
A name declared non-deprecated may be redeclared deprecated. A name declared deprecated cannot be un-deprecated by redeclaring it without this attribute.
Example
This section is incomplete Reason: no example |