iostreams icon indicating copy to clipboard operation
iostreams copied to clipboard

Removed deprecated-copy warning

Open chrisse74 opened this issue 3 years ago • 4 comments

Fixes several deprecated-copy warnings by using the BOOST_DEFAULTED_FUNCTION() macro.

chrisse74 avatar Jan 17 '23 11:01 chrisse74

This patch fails on C++03, because you need to provide a body for the function in the case that the compiler doesn't support = default.

So, for example, if you have:

template<typename T>
class device_close_operation {
public:
    typedef void result_type;
    device_close_operation(T& t, BOOST_IOS::openmode which) 
        : t_(t), which_(which) 
        { }
    void operator()() const { boost::iostreams::close(t_, which_); }
private:
    BOOST_DELETED_FUNCTION(device_close_operation& operator=(const device_close_operation&))
    T&                   t_;
    BOOST_IOS::openmode  which_;
};

you can't just add: BOOST_DEFAULTED_FUNCTION(device_close_operation(const device_close_operation&), {}); because that leaves the reference member t_ uninitialized.

Instead, you need to say something like: BOOST_DEFAULTED_FUNCTION(device_close_operation(const device_close_operation& rhs), : t_(rhs.t_) { which_ = rhs.which_; });

mclow avatar Jan 22 '23 00:01 mclow

Thanks for the explanation @mclow - working on it.

chrisse74 avatar Jan 26 '23 09:01 chrisse74

I had to drop three BOOST_DEFAULTED_FUNCTION() declarations (but commented this) to avoid "Uninitialized reference member" errors. Unfortunately the initializer list can only take one parameter, when using BOOST_DEFAULTED_FUNCTION.

chrisse74 avatar Jan 26 '23 10:01 chrisse74

I have also been trying to fix couple of these warnings in #154 (but less than this pull request). Would it be possible to consider one of these pull request ?

Also, i know some boost libraries dropped C++03 support in recent releases, I don't know if this is the case of boost iostream too.

Romain-Geissler-1A avatar Aug 15 '23 22:08 Romain-Geissler-1A