-
Tor Didriksen authored
GCC 9 has some new warnings. In particular, it now warns about use of implicit copy constructors in classes with nontrivial destructors (and in a few other cases, such as operator=), which is deprecated in C++11: class Foo { ~Foo(); // nontrivial destructor (even if it is actually empty) }; void func(Foo a) { // ... } Foo b; func(b); // warning, invoking implicit Foo(Foo &), which is deprecated for Foo The fix is either to remove ~Foo() where possible, or to make the copy constructor explicit: class Foo { ~Foo(); Foo(Foo &) = default; // now explicit, so no longer deprecated }; However, do note that making an explicit copy constructor disables the implicit assignment operator. If you want it, you'll need to specify it: class Foo { ~Foo(); Foo(Foo &) = default; Foo &operator=(const Foo &) = default; // must be explicit due to previous line }; And this, in turn, disables the implicit move assignment operator. Since you want it back, you need to write: class Foo { ~Foo(); Foo(Foo &) = default; Foo(Foo &&) = default; // move constructor must be explicit because copy is Foo &operator=(const Foo &) = default; Foo &operator=(Foo &&) = default; // move assignment must be explicit because move is }; This is all rather cumbersome for virtual base classes, but that's what the standard says, and GCC has chosen to warn on the standard. See GCC bug #58407. Change-Id: I3283d456728b664073673cd0e65f6fd932a04522
Tor Didriksen authoredGCC 9 has some new warnings. In particular, it now warns about use of implicit copy constructors in classes with nontrivial destructors (and in a few other cases, such as operator=), which is deprecated in C++11: class Foo { ~Foo(); // nontrivial destructor (even if it is actually empty) }; void func(Foo a) { // ... } Foo b; func(b); // warning, invoking implicit Foo(Foo &), which is deprecated for Foo The fix is either to remove ~Foo() where possible, or to make the copy constructor explicit: class Foo { ~Foo(); Foo(Foo &) = default; // now explicit, so no longer deprecated }; However, do note that making an explicit copy constructor disables the implicit assignment operator. If you want it, you'll need to specify it: class Foo { ~Foo(); Foo(Foo &) = default; Foo &operator=(const Foo &) = default; // must be explicit due to previous line }; And this, in turn, disables the implicit move assignment operator. Since you want it back, you need to write: class Foo { ~Foo(); Foo(Foo &) = default; Foo(Foo &&) = default; // move constructor must be explicit because copy is Foo &operator=(const Foo &) = default; Foo &operator=(Foo &&) = default; // move assignment must be explicit because move is }; This is all rather cumbersome for virtual base classes, but that's what the standard says, and GCC has chosen to warn on the standard. See GCC bug #58407. Change-Id: I3283d456728b664073673cd0e65f6fd932a04522
Loading