Disable warning C4251: "... needs to have dll-interface to be used by clients of class ..."

Viewed 4820

I am trying to workaround warning C4251: "... needs to have dll-interface to be used by clients of class ..." for STL classes in a less brutal way than wrapping every my class that uses STL with #pragma warning( push ) and #pragma warning( disable : 4251 ), then #pragma warning( pop ).

So to achieve that, I try to export whatever I can from STL templates like the code below. However, there are some private nested STL classes which I can't export this way. So I still have to wrap the blocks of export of public STL classes into warning-disabling code:

#ifdef SRPLATFORM_EXPORTS
#define SRPLATFORM_API __declspec(dllexport)
#else
#define SRPLATFORM_API __declspec(dllimport)
#endif // SRPLATFORM_EXPORTS

#pragma warning( push )
#pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
class SRPLATFORM_API std::exception_ptr;
template struct SRPLATFORM_API std::atomic<int32_t>;
class SRPLATFORM_API std::thread;
template SRPLATFORM_API class std::allocator<std::thread>;
template class SRPLATFORM_API std::vector<std::thread>; // this is line 19 in my file
#pragma warning( pop )

However, I am still getting C4251 for the nested private STL classes:

1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\vector(701): warning C4251: 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Mypair': class 'std::_Compressed_pair<std::_Wrap_alloc<std::allocator<std::thread>>,std::_Vector_val<std::_Simple_types<std::thread>>,true>' needs to have dll-interface to be used by clients of class 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>'
1>        with
1>        [
1>            _Ty=std::thread,
1>            _Alloc=std::allocator<std::thread>
1>        ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\vector(680): note: see declaration of 'std::_Compressed_pair<std::_Wrap_alloc<std::allocator<std::thread>>,std::_Vector_val<std::_Simple_types<std::thread>>,true>'
1>d:\dev\views\engines\probqa\srplatform\../SRPlatform/Interface/SRPlatform.h(19): note: see reference to class template instantiation 'std::vector<std::thread,std::allocator<std::thread>>' being compiled

So do I have to wrap in warning-disabling statements the include statements (like #include <vector>)? Or else, could someone clarify what's going on?

0 Answers
Related