Skip to content

Commit c17b30f

Browse files
Tweak definition of deprecation macros.
We now emit deprecation warnings on MSVC as well, and all deprecation warnings now include a string message, if possible.
1 parent e5bc5a8 commit c17b30f

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

.clang-format

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ AlwaysBreakBeforeMultilineStrings: false
5353
AlwaysBreakTemplateDeclarations: MultiLine
5454
AttributeMacros:
5555
- __capability
56+
- BSON_GNUC_WARN_UNUSED_RESULT
57+
- BSON_DEPRECATED
58+
- BSON_DEPRECATED_FOR
5659
BinPackArguments: false
5760
BinPackParameters: false
5861
BitFieldColonSpacing: Both

src/libbson/src/bson/bson-macros.h

+24-8
Original file line numberDiff line numberDiff line change
@@ -329,23 +329,39 @@ _bson_assert_failed_on_param (const char *param, const char *func)
329329
#define BSON_TYPEOF typeof
330330
#endif
331331

332+
/**
333+
* @brief Statically annotate an entity as deprecated, including the given deprecation message
334+
*
335+
* @param Message The message to be included in a deprecation warning. This
336+
* should be a string literal.
337+
*/
338+
#define BSON_DEPRECATED(Message) _bsonDeprecatedImpl (Message)
332339

333-
#if BSON_GNUC_CHECK_VERSION(3, 1)
334-
#define BSON_GNUC_DEPRECATED __attribute__ ((__deprecated__))
340+
// Pick the appropriate implementation of a deprecation attribute
341+
#if defined(_MSC_VER)
342+
// For MSVC, emit __declspec(deprecated(Msg))
343+
#define _bsonDeprecatedImpl(Msg) __declspec (deprecated (Msg))
344+
#elif defined(__GNUC__) && (defined(__clang__) || BSON_GNUC_CHECK_VERSION(4, 5))
345+
// For new enough Clang and GCC, emit __attribute__((__deprecated__(Msg)))
346+
#define _bsonDeprecatedImpl(Msg) __attribute__ ((__deprecated__ (Msg)))
347+
#elif defined(__GNUC__)
348+
// For older GCC, emit deprecation attribute without the message
349+
#define _bsonDeprecatedImpl(Msg) __attribute__ ((__deprecated__))
335350
#else
336-
#define BSON_GNUC_DEPRECATED
351+
// For other compilers, emit nothing
352+
#define _bsonDeprecatedImpl(Msg)
337353
#endif
338354

355+
#define BSON_DEPRECATED_FOR(F) BSON_DEPRECATED ("This API is deprecated. Use " #F " instead.")
356+
357+
#define BSON_GNUC_DEPRECATED BSON_DEPRECATED ("This API is deprecated")
358+
#define BSON_GNUC_DEPRECATED_FOR(F) BSON_DEPRECATED_FOR (F)
359+
339360
#define BSON_CONCAT_IMPL(a, ...) a##__VA_ARGS__
340361
#define BSON_CONCAT(a, ...) BSON_CONCAT_IMPL (a, __VA_ARGS__)
341362
#define BSON_CONCAT3(a, b, c) BSON_CONCAT (a, BSON_CONCAT (b, c))
342363
#define BSON_CONCAT4(a, b, c, d) BSON_CONCAT (BSON_CONCAT (a, b), BSON_CONCAT (c, d))
343364

344-
#if BSON_GNUC_CHECK_VERSION(4, 5)
345-
#define BSON_GNUC_DEPRECATED_FOR(f) __attribute__ ((deprecated ("Use " #f " instead")))
346-
#else
347-
#define BSON_GNUC_DEPRECATED_FOR(f) BSON_GNUC_DEPRECATED
348-
#endif
349365

350366
/**
351367
* @brief String-ify the given argument

0 commit comments

Comments
 (0)