mardi 9 février 2021

Whats the meaning of gcc/g++ error 'implicitly-declared' constructor is 'deprecated'?

I am trying to chase down errors coming out of upgrading my build system OS and gcc version with it to 9. I can demonstrate it with the following code.

class Cl {
        private:
                float f;
        public:
        constexpr float GetF() const { return f; }
        Cl& operator=(const Cl& other) {
                f = other.GetF();
                return *this;
        }
        Cl& operator=(const float& other) {
                this->f = other;
                return *this;
        }
        explicit constexpr Cl(const float& val) : f(val) {}
};

struct Sl {
        float x, y;
        Cl lcl;
        constexpr Sl(const float &init_x, const float &init_y, const Cl &cl) : x(init_x), y(init_y), lcl(cl) {}

};

typedef struct Sl sdata;

int main()
{
        const float fx = 30.30;
        Cl c1(fx);
        sdata s1(0, 0.0, c1);
        return 0;
}

Compiled with:

preetam@preetam-Precision-M4800 ~ $ g++-9 -Werror=deprecated-copy dp_test.cc 
dp_test.cc: In constructor ‘constexpr Sl::Sl(const float&, const float&, const Cl&)’:
dp_test.cc:22:101: error: implicitly-declared ‘constexpr Cl::Cl(const Cl&)’ is deprecated [-Werror=deprecated-copy]
   22 |  constexpr Sl(const float &init_x, const float &init_y, const Cl &cl) : x(init_x), y(init_y), lcl(cl) {}
      |                                                                                                     ^
dp_test.cc:8:6: note: because ‘Cl’ has user-provided ‘Cl& Cl::operator=(const Cl&)’
    8 |  Cl& operator=(const Cl& other) {
      |      ^~~~~~~~
cc1plus: some warnings being treated as errors`

Whats is the meaning of the error ?

Aucun commentaire:

Enregistrer un commentaire