Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/json/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@
#if defined(JSON_DLL_BUILD)
#if defined(_MSC_VER) || defined(__MINGW32__)
#define JSON_API __declspec(dllexport)
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
#elif defined(__GNUC__) || defined(__clang__)
#define JSON_API __attribute__((visibility("default")))
#endif // if defined(_MSC_VER)

#elif defined(JSON_DLL)
#if defined(_MSC_VER) || defined(__MINGW32__)
#define JSON_API __declspec(dllimport)
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
#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

#if defined(_MSC_VER)
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
#endif

#if !defined(JSON_API)
#define JSON_API
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/json/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// Disable warning C4251: <data member>: <type> needs to have dll-interface to
// be used by...
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER)
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma warning(push)
#pragma warning(disable : 4251)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Expand Down