Skip to content

Commit e9716fa

Browse files
authored
Problem: C++ version not correctly estimated (#429)
* Problem: C++ version not correctly estimated Solution: Include headers before checking macros and add additional checks for _MSVC_LANG.
1 parent bf4f75b commit e9716fa

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

zmq.hpp

+27-14
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,32 @@
3232
#endif
3333
#endif
3434

35+
// included here for _HAS_CXX* macros
36+
#include <zmq.h>
37+
38+
#if defined(_MSVC_LANG)
39+
#define CPPZMQ_LANG _MSVC_LANG
40+
#else
41+
#define CPPZMQ_LANG __cplusplus
42+
#endif
43+
// overwrite if specific language macros indicate higher version
44+
#if defined(_HAS_CXX14) && _HAS_CXX14 && CPPZMQ_LANG < 201402L
45+
#undef CPPZMQ_LANG
46+
#define CPPZMQ_LANG 201402L
47+
#endif
48+
#if defined(_HAS_CXX17) && _HAS_CXX17 && CPPZMQ_LANG < 201703L
49+
#undef CPPZMQ_LANG
50+
#define CPPZMQ_LANG 201703L
51+
#endif
52+
3553
// macros defined if has a specific standard or greater
36-
#if (defined(__cplusplus) && __cplusplus >= 201103L) \
37-
|| (defined(_MSC_VER) && _MSC_VER >= 1900)
54+
#if CPPZMQ_LANG >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
3855
#define ZMQ_CPP11
3956
#endif
40-
#if (defined(__cplusplus) && __cplusplus >= 201402L) \
41-
|| (defined(_HAS_CXX14) && _HAS_CXX14 == 1) \
42-
|| (defined(_HAS_CXX17) \
43-
&& _HAS_CXX17 \
44-
== 1) // _HAS_CXX14 might not be defined when using C++17 on MSVC
57+
#if CPPZMQ_LANG >= 201402L
4558
#define ZMQ_CPP14
4659
#endif
47-
#if (defined(__cplusplus) && __cplusplus >= 201703L) \
48-
|| (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
60+
#if CPPZMQ_LANG >= 201703L
4961
#define ZMQ_CPP17
5062
#endif
5163

@@ -80,14 +92,15 @@
8092
#define ZMQ_CONSTEXPR_VAR const
8193
#define ZMQ_CPP11_DEPRECATED(msg)
8294
#endif
95+
#if defined(ZMQ_CPP14) && (!defined(_MSC_VER) || _MSC_VER > 1900)
96+
#define ZMQ_EXTENDED_CONSTEXPR
97+
#endif
8398
#if defined(ZMQ_CPP17)
8499
#define ZMQ_INLINE_VAR inline
85100
#else
86101
#define ZMQ_INLINE_VAR
87102
#endif
88103

89-
#include <zmq.h>
90-
91104
#include <cassert>
92105
#include <cstring>
93106

@@ -1004,7 +1017,7 @@ class mutable_buffer
10041017
constexpr mutable_buffer() noexcept : _data(nullptr), _size(0) {}
10051018
constexpr mutable_buffer(void *p, size_t n) noexcept : _data(p), _size(n)
10061019
{
1007-
#ifdef ZMQ_CPP14
1020+
#ifdef ZMQ_EXTENDED_CONSTEXPR
10081021
assert(p != nullptr || n == 0);
10091022
#endif
10101023
}
@@ -1041,7 +1054,7 @@ class const_buffer
10411054
constexpr const_buffer() noexcept : _data(nullptr), _size(0) {}
10421055
constexpr const_buffer(const void *p, size_t n) noexcept : _data(p), _size(n)
10431056
{
1044-
#ifdef ZMQ_CPP14
1057+
#ifdef ZMQ_EXTENDED_CONSTEXPR
10451058
assert(p != nullptr || n == 0);
10461059
#endif
10471060
}
@@ -1273,7 +1286,7 @@ template<class Char, size_t N>
12731286
constexpr const_buffer str_buffer(const Char (&data)[N]) noexcept
12741287
{
12751288
static_assert(detail::is_pod_like<Char>::value, "Char must be POD");
1276-
#ifdef ZMQ_CPP14
1289+
#ifdef ZMQ_EXTENDED_CONSTEXPR
12771290
assert(data[N - 1] == Char{0});
12781291
#endif
12791292
return const_buffer(static_cast<const Char *>(data), (N - 1) * sizeof(Char));

0 commit comments

Comments
 (0)