Skip to content

Commit b6723ea

Browse files
committed
fix: avoid vs2015 type resolution confusion due to inline namespace
1 parent 97088e8 commit b6723ea

1 file changed

Lines changed: 36 additions & 17 deletions

File tree

includes/sjson/version.h

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,48 @@
3737
// within the same executable/library, the symbols have to be unique per version.
3838
// We achieve this by using a versioned namespace that we optionally inline.
3939
// To disable namespace inlining, define SJSON_CPP_NO_INLINE_NAMESPACE before including
40-
// any sjson-cpp header.
40+
// any sjson-cpp header. To disable the versioned namespace altogether,
41+
// define SJSON_CPP_NO_VERSION_NAMESPACE before including any sjson-cpp header.
4142
////////////////////////////////////////////////////////////////////////////////
4243

44+
#if !defined(SJSON_CPP_NO_VERSION_NAMESPACE)
45+
#if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER == 1900
46+
// VS2015 struggles with type resolution when inline namespaces are used
47+
// For that reason, we disable it explicitly
48+
#define SJSON_CPP_NO_VERSION_NAMESPACE
49+
#endif
50+
#endif
51+
4352
// Name of the namespace, e.g. v08
4453
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_NAME v ## SJSON_CPP_VERSION_MAJOR ## SJSON_CPP_VERSION_MINOR
4554

46-
#if defined(SJSON_CPP_NO_INLINE_NAMESPACE)
47-
// Namespace won't be inlined, its usage will have to be qualified with the
48-
// full version everywhere
49-
#define SJSON_CPP_IMPL_NAMESPACE sjson::SJSON_CPP_IMPL_VERSION_NAMESPACE_NAME
55+
#if defined(SJSON_CPP_NO_VERSION_NAMESPACE)
56+
// Namespace is inlined, its usage does not need to be qualified with the
57+
// full version everywhere
58+
#define SJSON_CPP_IMPL_NAMESPACE sjson
59+
60+
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_BEGIN
61+
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_END
62+
#elif defined(SJSON_CPP_NO_INLINE_NAMESPACE)
63+
// Namespace won't be inlined, its usage will have to be qualified with the
64+
// full version everywhere
65+
#define SJSON_CPP_IMPL_NAMESPACE sjson::SJSON_CPP_IMPL_VERSION_NAMESPACE_NAME
5066

51-
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_BEGIN \
52-
namespace SJSON_CPP_IMPL_VERSION_NAMESPACE_NAME \
53-
{
67+
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_BEGIN \
68+
namespace SJSON_CPP_IMPL_VERSION_NAMESPACE_NAME \
69+
{
70+
71+
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_END \
72+
}
5473
#else
55-
// Namespace is inlined, its usage does not need to be qualified with the
56-
// full version everywhere
57-
#define SJSON_CPP_IMPL_NAMESPACE sjson
74+
// Namespace is inlined, its usage does not need to be qualified with the
75+
// full version everywhere
76+
#define SJSON_CPP_IMPL_NAMESPACE sjson
5877

59-
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_BEGIN \
60-
inline namespace SJSON_CPP_IMPL_VERSION_NAMESPACE_NAME \
61-
{
62-
#endif
78+
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_BEGIN \
79+
inline namespace SJSON_CPP_IMPL_VERSION_NAMESPACE_NAME \
80+
{
6381

64-
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_END \
65-
}
82+
#define SJSON_CPP_IMPL_VERSION_NAMESPACE_END \
83+
}
84+
#endif

0 commit comments

Comments
 (0)