Skip to content

Commit

Permalink
src: fix NODE_DEPRECATED macro with old compilers
Browse files Browse the repository at this point in the history
The `__attribute__((deprecated("warning")))` macro didn't exist until
gcc 4.5 and clang 2.9.

While io.js does not build with compilers that old, add-ons do.  Let's
make src/node.h compatible with such compilers, it's a public header.

PR-URL: #1626
Refs: #1619
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis committed May 5, 2015
1 parent 71dc715 commit b712af7
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,33 @@
#include "v8.h" // NOLINT(build/include_order)
#include "node_version.h" // NODE_MODULE_VERSION

#if defined(__GNUC__)
# define NODE_DEPRECATED(message, declarator) \
#define IOJS_MAKE_VERSION(major, minor, patch) \
((major) * 0x1000 + (minor) * 0x100 + (patch))

#ifdef __clang__
# define IOJS_CLANG_AT_LEAST(major, minor, patch) \
(IOJS_MAKE_VERSION(major, minor, patch) <= \
IOJS_MAKE_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__))
#else
# define IOJS_CLANG_AT_LEAST(major, minor, patch) (0)
#endif

#ifdef __GNUC__
# define IOJS_GNUC_AT_LEAST(major, minor, patch) \
(IOJS_MAKE_VERSION(major, minor, patch) <= \
IOJS_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__))
#else
# define IOJS_GNUC_AT_LEAST(major, minor, patch) (0)
#endif

#if IOJS_CLANG_AT_LEAST(2, 9, 0) || IOJS_GNUC_AT_LEAST(4, 5, 0)
# define NODE_DEPRECATED(message, declarator) \
__attribute__((deprecated(message))) declarator
#elif defined(_MSC_VER)
# define NODE_DEPRECATED(message, declarator) \
# define NODE_DEPRECATED(message, declarator) \
__declspec(deprecated) declarator

This comment has been minimized.

Copy link
@tojocky

tojocky May 12, 2015

Why not to use message in MSC as well: "__declspec(deprecated(message)) declarator"?
Seems this is possible: https://msdn.microsoft.com/en-us/library/044swk7y.aspx

#else
# define NODE_DEPRECATED(message, declarator) \
# define NODE_DEPRECATED(message, declarator) \
declarator
#endif

Expand Down

2 comments on commit b712af7

@silverwind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis there are a few linter warnings introduced here:

src/node.h:51:  Weird number of spaces at line-start.  Are you using a 2-space indent?  [whitespace/indent] [3]
src/node.h:59:  Weird number of spaces at line-start.  Are you using a 2-space indent?  [whitespace/indent] [3]

@bnoordhuis
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, ain't that annoying. #1640

Please sign in to comment.