BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsla_deprecated

Macros

#define BSLA_DEPRECATED
 
#define BSLA_DEPRECATED_MESSAGE(message)
 

Detailed Description

Outline

Purpose

Provide compiler-hint macros to indicate deprecated entities.

Macros

See also
bsla_annotations

Description

This component provides preprocessor macros that hint to the compiler that a function, variable, type, typedef, struct member, enum type, or template specialization is deprecated. This is useful, for example, when identifying functions that are expected to be removed in a future version of a library.

Macro Reference

BSLA_DEPRECATED: This annotation will, when used, cause a compile-time warning if the so-annotated function, variable, type, typedef, struct member, enum type, or template specialization is used anywhere within the source file. The warning includes the location of the declaration of the deprecated entity to enable users to find further information about the deprecation, or what they should use instead.

BSLA_DEPRECATED_MESSAGE(QUOTED_MESSAGE): This annotation will, when used, cause a compile-time warning if the so-annotated function, variable, type, typedef, struct member, enum type, or template specialization is used anywhere within the source file. The compiler warning will contain the contents of the specified QUOTED_MESSAGE, which must be a double-quoted string. The warning includes the location of the declaration of the deprecated entity to enable users to find further information about the deprecation, and what they should use instead. Note that on some compilers QUOTED_MESSAGE is ignored.

BSLA_DEPRECATED_IS_ACTIVE: The macro BSLA_DEPRECATED_IS_ACTIVE is defined if BSLA_DEPRECATED and BSLA_DEPRECATED_MESSAGE are both active and have the desired effect; otherwise, BSLA_DEPRECATED_IS_ACTIVE is not defined and both other macros expand to nothing.

Usage

This section illustrates intended use of this component.

Example 1: Various Deprecations

First, we define a deprecated type UsageType:

struct BSLA_DEPRECATED UsageType {
int d_int;
};
#define BSLA_DEPRECATED
Definition bsla_deprecated.h:307

Then, we define a function usageFunc that is deprecated:

void usageFunc();
void usageFunc()
{
printf("Don't call me.\n");
}

Next, we define a variable usageVar that is deprecated:

BSLA_DEPRECATED extern int usageVar;
int usageVar = 5;

Then, we define a typedef UsageTypedef that is deprecated:

BSLA_DEPRECATED typedef int UsageTypedef;

Next, we define a struct with a member d_y that is deprecated:

struct UsageStruct {
double d_x;
BSLA_DEPRECATED double d_y;
};

Then, we define an enum UsageEnum that is deprecated:

enum BSLA_DEPRECATED UsageEnum { e_FALSE, e_TRUE };

Next, we define a template this is only deprecated in the case where it is specialized with the int type as a template parameter:

template <class TYPE>
TYPE usageAbs(TYPE x)
{
return x < 0 ? -x : x;
}
template <>
BSLA_DEPRECATED_MESSAGE("'int' specialization not allowed")
int usageAbs<int>(int x)
{
int ret = x < 0 ? -x : x;
return ret < 0 ? ~ret : ret;
}
#define BSLA_DEPRECATED_MESSAGE(message)
Definition bsla_deprecated.h:308

Then, as long as we don't use them, no warnings will be issued.

Next, we use UsageType:

UsageType ut;
ut.d_int = 5;
(void) ut.d_int;

which results in the following warnings:

.../bsla_deprecated.t.cpp:287:5: warning: 'UsageType' is deprecated
[-Wdeprecated-declarations]
UsageType ut;
^
.../bsla/bsla_deprecated.t.cpp:113:7: note: 'UsageType' has been explicitly
marked deprecated here
^

Then, we call usageFunc:

usageFunc();

which results in the following warnings:

.../bsla_deprecated.t.cpp:309:5: warning: 'usageFunc' is deprecated
[-Wdeprecated-declarations]
usageFunc();
^
.../bsla_deprecated.t.cpp:117:22: note: 'usageFunc' has been explicitly
marked deprecated here
void usageFunc() BSLA_DEPRECATED;
^

Next, we access usageVar:

printf("%d\n", usageVar);

which results in the following warnings:

.../bsla_deprecated.t.cpp:326:20: warning: 'usageVar' is deprecated
[-Wdeprecated-declarations]
printf("%d\n", usageVar);
^
.../bsla_deprecated.t.cpp:134:25: note: 'usageVar' has been explicitly
marked deprecated here
extern int usageVar BSLA_DEPRECATED;
^
.../bsla_deprecated.h:119:32: note: expanded from macro 'BSLA_DEPRECATED'
# define BSLA_DEPRECATED [[deprecated]]

Then, we use UsageTypedef:

UsageTypedef jjj = 32;
(void) jjj;

which results in the following warnings:

.../bsla_deprecated.t.cpp:379:5: warning: 'UsageTypedef' is deprecated
[-Wdeprecated-declarations]
UsageTypedef jjj = 32;
^
.../bsla_deprecated.t.cpp:140:5: note: 'UsageTypedef' has been explicitly
marked deprecated here
BSLA_DEPRECATED typedef int UsageTypedef;
^

Next, we access the deprecated member of UsageStruct:

UsageStruct us;
::memset(&us, 0, sizeof(us));
assert(0 == us.d_x); // no warning
assert(0 == us.d_y); // 'd_y' is deprecated -- issues warning.

which results in the following warnings:

.../bsla_deprecated.t.cpp:387:20: warning: 'd_y' is deprecated
[-Wdeprecated-declarations]
assert(0 == us.d_y); // 'd_y' is deprecated -- issues warning.
^
.../bsla_deprecated.t.cpp:146:9: note: 'd_y' has been explicitly marked
deprecated here
BSLA_DEPRECATED double d_y;
^

Now, we use the deprecated UsageEnum:

UsageEnum ue;
ue = e_TRUE;
(void) ue;

which results in the following warnings:

.../bsla_deprecated.t.cpp:411:15: warning: 'UsageEnum' is deprecated
[-Wdeprecated-declarations]
UsageEnum ue;
^
.../bsla_deprecated.t.cpp:152:26: note: declared here
enum BSLA_DEPRECATED UsageEnum { e_FALSE, e_TRUE };
^

Finally, we access the deprecated specialization of usageAbs:

assert(2.0 == usageAbs(-2.0)); // no warning, 'usageAbs<double>'
// not deprecated
assert(INT_MAX == usageAbs(INT_MIN)); // warning, 'usageAbs<int>' is
// deprecated

which results in the following warnings:

.../bsla_deprecated.t.cpp:441:39: warning: 'TYPE usageAbs(TYPE) [with TYPE
= int]' is deprecated: 'int' specialization not allowed
[-Wdeprecated-declarations]
assert(INT_MAX == usageAbs(INT_MIN)); // warning, 'usageAbs<int>'
^
.../bsla_deprecated.t.cpp:168:9: note: declared here
int usageAbs<int>(int x)
^~~~~~~~~~~~~

Macro Definition Documentation

◆ BSLA_DEPRECATED

#define BSLA_DEPRECATED

◆ BSLA_DEPRECATED_MESSAGE

#define BSLA_DEPRECATED_MESSAGE (   message)