This is not a breaking issue but I like to clean my code from warnings so this is getting on my nerves.
I have been using the c++11 version of pimpl idiom to hide the class implementation for my library the usual way.
// dll header
class FrameworkImpl;
class EXPORT_API Framework
{
Framework(const Framework&) = delete;
Framework& operator=(const Framework&) = delete;
Framework(Framework&&) = delete;
Framework& operator=(Framework&&) = delete;
public:
Framework();
~Framework();
private:
std::unique_ptr<FrameworkImpl> impl_;
};
// application implementation
int main()
{
std::unique_ptr<Framework> test = std::make_unique<Framework>();
}
Everything will be fine, but I will keep getting the warning:
warning C4251: 'Framework::impl_': class 'std::unique_ptr<FrameworkImpl,std::default_delete<_Ty>>' needs to have dll-interface to be used by clients of class 'Framework'
So I tried have to add:
template class EXPORT_API std::unique_ptr<FrameworkImpl>;
Before the forward declaration but the warning would just change to:
warning C4251: 'std::_Unique_ptr_base<_Ty,_Dx>::_Mypair': class 'std::_Compressed_pair<_Dx,FrameworkImpl *,true>' needs to have dll-interface to be used by clients of class 'std::_Unique_ptr_base<_Ty,_Dx>'
I have being seeing this issue since VS2010 and I cannot figure a good way to fix this. No problems on gcc or clang and it would break my heart to use the old raw pointer version..
std::unique_ptr<FrameworkImpl> impl_;
withstruct do_nothing{ template<class T> void operator()(T&&)const{}; }; std::unique_ptr<FrameworkImpl, do_nothing> impl_;
-- I want to see if it is related to the default deleter. (if this does compile, you aren't done! but it is diagnostic.) Also note that the warning might be spurious. – Yt