How do obsolete warnings work and how to remove them when using JsonCpp?

I compiled with VS 2015 jsoncpp and can link to it and everything works fine.

However, I get tones of outdated warnings. Some classes are marked as defective in code:

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

with

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

The thing is, I do not use these classes. I get messages as soon as the file is included. Compilation:

#include <json/json.h>

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

    return 0;
}

Produces 13 obsolete warnings ...

Shouldn't these warnings only be reported when using an obsolete class / function? is there any way to make it work this way? (I could turn off warning C4996, but it would be better if it was turned on, but only reported if the legacy class / function was actually used).

+4
2

, , Writer. . , .

EDIT: . 5 , .

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 7   warning C4996: 'UnusedClass': Depricated Warning UnusedClass    C:\Users\admin\Documents\Test.h 144
+3

@FlosAwsm , , Writer ( ).

, , , jsoncpp.

+++ include/json/writer.h
+#pragma warning(push)
+#pragma warning(disable:4996) // Deriving from deprecated class
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter : public Writer {
+#pragma warning(pop)

+#pragma warning(push)
+#pragma warning(disable:4996) // Deriving from deprecated class  
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledWriter : public Writer {  
+#pragma warning(pop)  

, FastWriter StyledWriter, Writer. , , .

( Writer ) - ( ).

+1

Source: https://habr.com/ru/post/1685433/


All Articles