Skip to content
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

Closed
t-b opened this issue Feb 27, 2020 · 4 comments
Closed

Comments

@t-b
Copy link

t-b commented Feb 27, 2020

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.

@nemequ
Copy link
Owner

nemequ commented Feb 27, 2020

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)

@t-b
Copy link
Author

t-b commented Feb 27, 2020

@nemequ Sounds good! Thanks for the quick reply.

@nemequ
Copy link
Owner

nemequ commented Mar 18, 2020

I just tagged v13, this workaround is included.

@nemequ nemequ closed this as completed Mar 18, 2020
@t-b
Copy link
Author

t-b commented Mar 18, 2020

@nemequ Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants