6

I got sent a link describing a [[deprecated]] attribute in C++11. This sound pretty convenient, and I would like to have more information about it - which compilers support it, full documentation on it, etc.

I spent 20 minutes or so googling around, but apart from the linked website, I couldn't find infos on this anywhere. Partly, this was complicated by other uses of the word "deprecated" in connection with C++11, and search engines not recognizing [[. I didn't find this in draft standards linked to in various SO answers, either. I don't have access to the full, paid, standard.

Does anybody have more information about this [[deprecated]] attribute?

P.S.: If you're curious, I'd use this as a better alternative to https://stackoverflow.com/a/295229/599884

Community
  • 1
  • 1
Christoph
  • 5,480
  • 6
  • 36
  • 61

2 Answers2

12

The [[deprecated]] attribute has made its way into the draft of C++14 (see section 7.6.5 [dcl.attr.deprecated] of the October 2013 draft).

The attribute-token deprecated can be used to mark names and entities whose use is still allowed, but is discouraged for some reason.

For example, the following function foo is deprecated:

[[deprecated]]
void foo(int);

It is possible to provide a message that describes why the name or entity was deprecated:

[[deprecated("Replaced by bar, which has an improved interface")]]
void foo(int);

The message must be a string literal.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • a link to the draft doc would be great :-) edit: thanks! – Christoph Jan 17 '14 at 16:24
  • A nice reference about attributes (as well as many other C/C++ language and standard libraries features) is cppreference.com. See http://en.cppreference.com/w/cpp/language/attributes for `[[deprecated]]`. – TManhente Feb 08 '14 at 14:33
7

First, things in [[]] are not keywords; they are attributes.

Second, there is no [[deprecated]] attribute defined by the C++11 standard. The link you're referring to is either in error or referring to a specific compiler (C++Builder, perhaps?) that implements this attribute.

Attributes are (usually) compiler specific. Like #pragmas, compilers are supposed to ignore any attribute they don't support.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • thanks. keyword felt wrong somehow, but I wasn't sure, so I took the "Go Up to Keywords" link on that page to mean that it's a keyword. corrected. And thanks for the answer. – Christoph Jun 13 '12 at 14:59
  • @Nicol: "compilers are supposed to ignore any attribute they don't support". That sounds logical, but where do I find that in the standard, please? I remember looking for it some time ago, in vain. – Marc Mutz - mmutz Jun 13 '12 at 15:44
  • 1
    @Marc : §7/1: "*Except where otherwise specified, the meaning of an attribute-declaration is implementation-defined.*". §7.6.1/5: "*For an attribute-token not specified in this International Standard, the behavior is implementation-defined.*" Supposed to, not required to. :-] – ildjarn Jun 13 '12 at 17:22
  • 1
    I know this is just a "thank you" comment, but still, it is nice to read about this feature because it has been there for years in other modern languages like Java... – László Papp Nov 28 '13 at 11:50