Skip to content

/Zc:__cplusplus leads to C2416 #1695

Closed

Description

@crusader-mike

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.

Activity

  1. jaredgrubb commented on Jul 31, 2019

    @jaredgrubb
    Contributor

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

  2. crusader-mike commented on Jul 31, 2019

    @crusader-mike
    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.

  3. jaredgrubb commented on Aug 1, 2019

    @jaredgrubb
    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 :)

  4. stale commented on Sep 2, 2019

    @stale

    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.

  5. added
    state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated
    on Sep 2, 2019
  6. crusader-mike commented on Sep 3, 2019

    @crusader-mike
    Author

    Bad bot!

  7. removed
    state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated
    on Sep 3, 2019
  8. t-b commented on Sep 3, 2019

    @t-b
    Contributor

    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.

  9. crusader-mike commented on Sep 4, 2019

    @crusader-mike
    Author

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

  10. stale commented on Oct 4, 2019

    @stale

    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.

  11. added
    state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated
    on Oct 4, 2019
  12. mrstux commented on Oct 23, 2019

    @mrstux

    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://github.com/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.

  13. 12 remaining items

  14. LanderlYoung commented on Mar 4, 2020

    @LanderlYoung

    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.

  15. t-b commented on Mar 18, 2020

    @t-b
    Contributor

    @LanderlYoung The upstream bug in hedley was fixed.

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

  16. dota17 commented on Mar 18, 2020

    @dota17
    Contributor

    @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.

  17. nlohmann commented on Mar 19, 2020

    @nlohmann
    Owner

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

  18. t-b commented on Mar 19, 2020

    @t-b
    Contributor

    @nlohmann Yeep, I've rebased #1958.

  19. self-assigned this
    on Apr 10, 2020
  20. added this to the Release 3.7.4 milestone on Apr 10, 2020
  21. kenr commented on Jun 2, 2020

    @kenr

    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.

  22. nlohmann commented on Jun 3, 2020

    @nlohmann
    Owner

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

  23. kenr commented on Jun 4, 2020

    @kenr

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

  24. nlohmann commented on Jun 4, 2020

    @nlohmann
    Owner

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

  25. added 2 commits that reference this issue on Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions