Search code examples
c++jsoncppdeprecation-warning

How works deprecated warnings and how to remove them when using JsonCpp?


I compiled with VS 2015 jsoncpp and am able to link with it and everythign works fine.

However, I'm getting tones of deprecated warnings. Some classes are marked as depecrated in the code:

class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {...};

with

#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))

Thing is I don't use those classes. I'm getting the messages as soon as the file is included. Compiling this:

#include <json/json.h>

int main( int argc, char* argv[] )
{

    return 0;
}

Produces 13 deprecated warnings...

Isn't those warnings only supposed to be reported when a deprecated class/function is used? is there a way to have it work this way? (I could disable warning C4996, but it would be better to keep it enabled, but only reported when a deprecated class/function is actually used).


Solution

  • I think the problem is, that some classes derive from Writer. This counts as being used. I have no idea how to get rid of the warnings, though.

    EDIT: Tested it. It produces the same warning 5 times, without being used.

    test.h

    class __declspec(deprecated("Depricated Warning UnusedClass")) UnusedClass
    {
    public:
        void SetI(int &val);
    };
    
    class __declspec(deprecated("Depricated Warning UnusedClass")) UnusedClass2 : UnusedClass
    {
    public:
        int GetI();
        int i;
    };
    

    test.cpp

    void UnusedClass::SetI(int &val)
    {
        val = 0;
    }
    
    int UnusedClass2::GetI()
    {
        return 10;
    }
    

    Warning:

    Warning 7   warning C4996: 'UnusedClass': Depricated Warning UnusedClass    C:\Users\admin\Documents\Test.h 144