Skip to content

Conversation

Biswa96
Copy link

@Biswa96 Biswa96 commented Aug 19, 2020

No description provided.

@coveralls
Copy link

coveralls commented Aug 19, 2020

Coverage Status

Coverage remained the same at 93.801% when pulling 8a1ad08 on Biswa96:add-msvc-ifdef into 5be07bd on open-source-parsers:master.

Copy link
Contributor

@BillyDonahue BillyDonahue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of modifying every instance of #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING),
we can just go find where JSONCPP_DISABLE_DLL_INTERFACE_WARNING is defined and force it to be false unless _MSC_VER is defined. The JSONCPP_.... macros are supposed to be stand-alone and not require compound conditions like this.

#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER)
#pragma warning(pop)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just delete the comments on these #endif statements if the block is small and leafy like this. It's lame to keep them up to date as the #if condition evolves.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked at json/src/config.h and we already do what I'm requesting.
The JSONCPP_DISABLE_DLL_INTERFACE_WARNING is only defined if _MSC_VER is defined.
This is by design. I don't think your PR will improve anything. Do you have a motivating case like a build failure you can provide?

@Biswa96
Copy link
Author

Biswa96 commented Aug 20, 2020

I have change the code and add a little explanation.

* File changes: include/json/{config.h, writer.h}
* Summary: previously JSONCPP_DISABLE_DLL_INTERFACE_WARNING is defined
  when _MSC_VER or __MINGW32__ defined. So, when compiled with GCC or
  Clang using MinGW toolchain those #pragma warnings are also enabled.
  This change enables those #pragma warnings only when MSVC is used
  i.e. only when _MSC_VER is defined.
#endif // if defined(_MSC_VER)
#endif // ifdef JSON_DLL_BUILD

// Disable MSVC specific compiler warnings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro used to only get defined when JSON_DLL_BUILD is defined.
I think it should stay that way, as it's clearly only relevant to DLL builds. Move it back up into the preceding #if block.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it was defined in both JSON_DLL_BUILD and JSON_DLL sections. What's the issue with current change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misread and thought JSON_DLL was nested inside JSON_DLL_BUILD.
So looking at the if/else structure here, we have 3 relevant modes. JSON_DLL, JSON_DLL_BUILD, and everything else.

I think JSONCPP_DISABLE_DLL_INTERFACE_WARNING should only be engaged when we're making a DLL target AND we're using a MSFT compiler. I think we should only disable the warnings when we expect to generate them and need to silence them. We don't need this warning silenced if JSON_API doesn't expand into a dll-related declspec. If we're not building with DLL interface declspecs, we are silencing a warning unnecessarily and we don't need to do that. So I think we should be extremely conservative in turning off warnings. So:

#if defined(_MSC_VER) && (defined (JSON_DLL) || defined(JSON_DLL_BUILD))
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
#endif

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But JSONCPP_DISABLE_DLL_INTERFACE_WARNING is defined in include/json files. So, if a project includes those header files MSVC compiler shows warnings due to jsoncpp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looping back around to this. I think the confusion is that the warnings you are seeing are NOT DLL_INTERFACE_WARNINGs. This should really be renamed to:

JSONCPP_DISABLE_MSVC_WARNINGS

@baylesj
Copy link
Contributor

baylesj commented Nov 6, 2020

It's still not clear to me what the actual error that is happening in MSVC, and how this fixes it. @Biswa96 can you show the compiler output?

@Biswa96
Copy link
Author

Biswa96 commented Nov 7, 2020

The error is not happening with MSVC, it's with GCC and/or Clang. First read the commit message. The #pragma warning are for MSVC, so my preprocessor changes check it first then enables it. Without it GCC show multiple warnings like this:

In file included from ../include/json/reader.h:11,
                 from ../src/lib_json/json_reader.cpp:10:
../include/json/value.h:52: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
   52 | #pragma warning(push)
      |
../include/json/value.h:53: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
   53 | #pragma warning(disable : 4251)
      |
../include/json/value.h:932: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  932 | #pragma warning(pop)
      |

@BillyDonahue
Copy link
Contributor

The error is not happening with MSVC, it's with GCC and/or Clang. First read the commit message. The #pragma warning are for MSVC, so my preprocessor changes check it first then enables it. Without it GCC show multiple warnings like this:

In file included from ../include/json/reader.h:11,
                 from ../src/lib_json/json_reader.cpp:10:
../include/json/value.h:52: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
   52 | #pragma warning(push)
      |
../include/json/value.h:53: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
   53 | #pragma warning(disable : 4251)
      |
../include/json/value.h:932: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  932 | #pragma warning(pop)
      |

You said here: #1212 (comment)

But JSONCPP_DISABLE_DLL_INTERFACE_WARNING is defined in include/json files. So, if a project includes those header files MSVC compiler shows warnings due to jsoncpp.

What MSVC compiler warnings are we talking about in THAT case?

@Biswa96
Copy link
Author

Biswa96 commented Dec 14, 2020

The warnings in #pragma warning(disable).

@Biswa96 Biswa96 closed this by deleting the head repository Oct 11, 2023
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

Successfully merging this pull request may close these issues.

4 participants