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

/Zc:__cplusplus leads to C2416 #1695

Closed
crusader-mike opened this issue Jul 31, 2019 · 24 comments · Fixed by #1958
Closed

/Zc:__cplusplus leads to C2416 #1695

crusader-mike opened this issue Jul 31, 2019 · 24 comments · Fixed by #1958
Assignees
Labels
kind: bug platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@crusader-mike
Copy link

OS: Windows 7
Compiler: MSVC 2017 (15.9.11)

If project uses /Zc:__cplusplus json lib v3.7.0 fails to compile with this:

C2416: attribute 'deprecated' cannot be applied in this context

Looks like MSVC doesn't like this attribute applied to operator>> definition.

@jaredgrubb
Copy link
Contributor

I don't see why there is any bug here. Can you explain why the deprecated attribute is not legal in that context?

@crusader-mike
Copy link
Author

I assume it complains because [[deprecated]] attribute was applied to definition. According to C++17 draft I have (10.6.4.p2):

The attribute may be applied to the declaration of a class, a typedef-name, a variable, a non-static data member, a function, a namespace, an enumeration, an enumerator, or a template specialization.

Looks like MS read it as "can't happen on a definition". I have no opinion about correctness of this position.

@jaredgrubb
Copy link
Contributor

Yeh, that's a nuance that I can't make a call on myself. Dumb fix would be just to disable C2416 for this file :)

@nlohmann nlohmann added the platform: visual studio related to MSVC label Aug 3, 2019
@stale
Copy link

stale bot commented Sep 2, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Sep 2, 2019
@crusader-mike
Copy link
Author

Bad bot!

@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Sep 3, 2019
@t-b
Copy link
Contributor

t-b commented Sep 3, 2019

Not sure how the project rules here are with respect to selectively disabling warnings but why not propose a PR which uses pragma push/pop logic for MSVC to disable that warning for this piece of code? See https://stackoverflow.com/a/18463996 as a starting point.

@crusader-mike
Copy link
Author

or I could simply patch this lib in my vcpkg instance and avoid dealing with PR/etc ;)

@stale
Copy link

stale bot commented Oct 4, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Oct 4, 2019
@stale stale bot closed this as completed Oct 11, 2019
@mrstux
Copy link

mrstux commented Oct 23, 2019

I'm seeing this too.

I tried disabling the warning via the push/pop mechanism, but it seems the compiler front-end doesn't understand that its a compiler warning, and the website doesn't document it either.

In the end I added a check for MSVC to the deprecated language checks. Oh well.

A bit hacky, but unblocking.

/*
TODO: remove _MSC_VER when this is fixed.
https:/nlohmann/json/issues/1695
*/
#if defined(__cplusplus) && (__cplusplus >= 201402L) && !defined(_MSC_VER)
    #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
    #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
#elif \

And regarding closing this issue because its "stale", I guess its a novel approach to solving issues, just close them after 31 days.

@nlohmann
Copy link
Owner

This should be fixed on develop branch as it contains an updated version of Hedley. Can anyone try this?

@nlohmann nlohmann reopened this Oct 23, 2019
@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Oct 23, 2019
@t-b
Copy link
Contributor

t-b commented Oct 23, 2019

I've added a PR which compiles with /Zc:__cplusplus. Let's see if that works now.

@t-b
Copy link
Contributor

t-b commented Oct 23, 2019

Fails in CI as well, see https://ci.appveyor.com/project/nlohmann/json/builds/28319126/job/qp8uvagt7i56g5bp.

@mrstux The best thing here is to fix the issue in https:/nemequ/hedley, then incorporat the changes into the linked PR.

@t-b
Copy link
Contributor

t-b commented Nov 2, 2019

It's not about the definition. MSVC chokes on the friend. Using "__declspec(deprecated)" does not trigger the warning. see https://godbolt.org/z/lhPjC-.

@stale
Copy link

stale bot commented Dec 2, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Dec 2, 2019
@stale stale bot closed this as completed Dec 9, 2019
@t-b
Copy link
Contributor

t-b commented Feb 27, 2020

@nlohmann Please reopen.

@nlohmann nlohmann reopened this Feb 28, 2020
@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Feb 28, 2020
@LanderlYoung
Copy link

LanderlYoung commented Mar 4, 2020

Is there any progress here?

As far as I know, the easy way is to disable the attribute for windows by:

#if defined(__cplusplus) && (__cplusplus >= 201402L) && !defined(_MSC_VER)

BTW: MSVC sucks on this and the __cplusplus Marco bug.

Also, once MSVC fixed it, the last condition can be checking _MSC_VER range.

@t-b
Copy link
Contributor

t-b commented Mar 18, 2020

@LanderlYoung The upstream bug in hedley was fixed.

@nlohmann How do I upgrade to a newer hedley version?

@dota17
Copy link
Contributor

dota17 commented Mar 18, 2020

@t-b
I had compared the current version and the newest version of hedley.
There are not a lot of differences or special changes. So it maybe ok to update the source codes.

@nlohmann
Copy link
Owner

nlohmann commented Mar 19, 2020

I upgraded Hedley to version 13 in https:/nlohmann/json/tree/feature/update_hedley - can someone check if this fixes this issue? @t-b ?

@t-b
Copy link
Contributor

t-b commented Mar 19, 2020

@nlohmann Yeep, I've rebased #1958.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Apr 10, 2020
@nlohmann nlohmann self-assigned this Apr 10, 2020
@nlohmann nlohmann added this to the Release 3.7.4 milestone Apr 10, 2020
@kenr
Copy link

kenr commented Jun 2, 2020

Is the 3.7.4/3.4.0 release with this fix planned anytime soon? I use bitsery with std::variant and that requires /Zc:__cplusplus for MSVC to set the correct __cplusplus value for C++17.

@nlohmann
Copy link
Owner

nlohmann commented Jun 3, 2020

The next release will be version 3.8.0. I'm not sure how much more time I will need until it is ready.

@kenr
Copy link

kenr commented Jun 4, 2020

@nlohmann Is there anything I can help out with towards the 3.8.0 release?

@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2020

Not really - but if you are using MSVC and want to help, you may want to have a look at #2117.

koprok pushed a commit to koprok/vcpkg that referenced this issue Jun 26, 2020
This reverts commit ef90276.

Because 3.7.3 does not build with MSVC 2017.
See nlohmann/json#1695 for details.
koprok pushed a commit to koprok/vcpkg that referenced this issue Jun 26, 2020
…#7459)"

This reverts commit 67dd3a8.

Because 3.7.0 does not build with MSVC 2017.
See nlohmann/json#1695 for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
8 participants