deprecated

From RAD Studio
Jump to: navigation, search

Go Up to Keywords, Alphabetical Listing Index


Note: This feature is available only for the classic bcc32 compiler, not for the modern Clang-enhanced compiler.

Syntax

<entity declaration> [[deprecated]]

or

<entity declaration> [[deprecated("message")]]

Description

Use the deprecated attribute to flag your user-defined constructs as deprecated. A deprecated construct is old or outdated, can be replaced by a better substitute, is not supposed to be used anymore, or might not be supported in the future.

If a deprecated construct is found, a W8111 Accessing deprecated entity %s (C++) warning is thrown. The warning is thrown for any type of deprecated entity, including variables of a deprecated type.

The second form of the syntax allows users to output a message in the warning. The message usually recommends the newer construct that should be used.

Note: The deprecated attribute is not supported for C++ Audits. Consider instead the _DEPRECATED_ATTRIBUTE0 and _DEPRECATED_ATTRIBUTE1 predefined macros.

The warning message is issued if the entity declared as deprecated is used in code, otherwise not.

The constructs that support the deprecated attribute are as follows:

Enums

enum myEnum [[deprecated]] { e0, e1, e2 };
myEnum e = e1; //W8111 Accessing deprecated entity 'myEnum'

Global Functions/Variables

int x [[deprecated]];
void myFunc(int, int) [[deprecated("use myFunc(int,double) instead")]] {
}
void myFunc(int, double){
}

//...
myFunc(3,3); //W8111 Accessing deprecated entity 'myFunc(int,int)' use myFunc(int,double) instead

Classes/Structs

class A [[deprecated]] {
} a0; //Warning

struct B [[deprecated]] {
} b0; //Warning
class C : A{
}

//...
C c0; //W8111 Accessing deprecated entity 'A'
Note: A warning is thrown when the class/struct is accessed; in this case, when the class/struct is instantiated. A deprecated ancestor also outputs a warning.

Methods and Fields

class A{
 public:
  int m_x [[deprecated]];
  int m_y [[deprecated]];
  A(int x, double y){}
  A(int x, int y) [[deprecated("use the A(int,double) constructor")]]{} //W8111 Accessing deprecated entity 'A::A(int,int)' use the A(int,double) constructor
} a0(5,6);

//...
A a1(5,1.0);//No warning
a1.m_x=5; //W8111 Accessing deprecated entity 'A::m_x'
Note: In these cases, the warning outputs the class name before the member name.

Template Classes

template <class T> class A  {
 public:
  template <class T> class B  [[deprecated]] {};
};

//...
A<int>::B<double> a0; //W8111 Accessing deprecated entity 'A<int>::B<double>'
Note: When compiling Delphi components, when the unit is translated into C++ (generating .hpp files), if some constructs are flagged as deprecated in the original unit, they are also marked as deprecated in the .hpp.

Example

In SysUtils.hpp:

 class PASCALIMPLEMENTATION EStackOverflow [[deprecated]] : public EExternal

Portability

POSIX Win32 Win64 ANSI C ANSI C++

deprecated

+

Note: The deprecated attribute is not supported by Clang-enhanced C++ compilers. See Workaround for C++11 Attributes (Clang-enhanced C++ Compilers).

See Also