-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSVC with /Zc:__cplusplus and deprecated on a friend function does not compile #33
Comments
Interesting. Looks like this was fixed in VS2019. There is really no way to control which implementation is used based on where it is in the code (i.e.,, we can't use __declspec on friends but an attribute elsewhere). In this case, though, I don't see much reason to prefer a C++ attribute over the declspec version, so how about just prioritizing the declspec version by moving the check to before the C++ version check? diff --git a/hedley.h b/hedley.h
index 2ce91f3..db73760 100644
--- a/hedley.h
+++ b/hedley.h
@@ -928,7 +928,10 @@
#if defined(HEDLEY_DEPRECATED_FOR)
# undef HEDLEY_DEPRECATED_FOR
#endif
-#if defined(__cplusplus) && (__cplusplus >= 201402L)
+#if HEDLEY_MSVC_VERSION_CHECK(14,0,0)
+# define HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
+# define HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
+#elif defined(__cplusplus) && (__cplusplus >= 201402L)
# define HEDLEY_DEPRECATED(since) HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
# define HEDLEY_DEPRECATED_FOR(since, replacement) HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
#elif \
@@ -962,9 +965,6 @@
HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
# define HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
# define HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
-#elif HEDLEY_MSVC_VERSION_CHECK(14,0,0)
-# define HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
-# define HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
#elif \
HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
HEDLEY_PELLES_VERSION_CHECK(6,50,0) |
@nemequ Sounds good! Thanks for the quick reply. |
I just tagged v13, this workaround is included. |
@nemequ Thanks! |
I'm coming from nlohmann/json#1695.
The problem is that
HEDLEY_DEPRECATED_FOR
does not work in some cases for MSVC when /Zc:__cplusplus is set. https://godbolt.org/z/zh8AJB is a short example demonstrating the issue and nlohmann/json#1958 is a PR which currently fails due to that.The text was updated successfully, but these errors were encountered: