jerett-cc / ryujin

High-performance high-order finite element solver for hyperbolic conservation equations
https://conservation-laws.org
Other
0 stars 0 forks source link

Warning -W depricated-copy for an operator= #33

Open jerett-cc opened 3 months ago

jerett-cc commented 3 months ago

@bangerth The warning I see is Screenshot from 2024-05-28 13-08-07 where the two relevant pieces of code are in the files /source/my_app.template.h and /source/multicomponent_vector.h

see screenshot. Screenshot from 2024-05-28 13-09-03

My understanding from reading about this warning online is that it can be fixed my explicitly writing default for all the base class operators (MultiComponentVector derives from dealii::distributed::vector)

as in MultiComponentVector& operator=(const MultiComponentVector & in_v) = default;. When I tried this intially within the class, other warnings pop up from other parts of ryujin. This is likely because there are two other dealii::distributed::vector::operator=() that exist and need to be dealt with similarly?

Bottom line, it seems that the line using ScalarVector::operator=; may be the culprit somehow.

bangerth commented 3 months ago

The warning is strictly speaking harmless. What it says is that the code as is written is legal in the language you are compiling (which currently is C++17) but may no longer be in future language standards (such as C++20 or C++23). In essence, it boils down to the fact that when you have a class such as

  class X {
    public:
       X() : my_member(42) {}
    private:
       int my_member;
  };

then in order to allow for things such as

  X a;
  X b;
  b = a;

the compiler needs to create an operator= for class X. Because the authors of the class didn't create one explicitly, the compiler does that by itself, which looks like

  X& operator= (const X&other) {
    this->my_member = other.my_member;
    return *this;
  }

For the case here, this is unambiguous. For more complicated cases, where you have classes derived from each other or where there are members that aren't just simple values, there are some ambiguities and the compiler is telling you that the authors of the C++ standard intend to remove the language that says that the compiler can create the copy operator itself -- i.e., that code authors will be forced to write one themselves.

One way to write one yourself is to add

  MultiComponentVector& operator=(const MultiComponentVector & in_v) = default;

to your code. Basically you're telling the compiler "hey, I want this operator; please create it in the same way as you would if you'd do it implicitly". That should work. If you get follow-up warnings about this, let me see what you get.