Open Bug 1229476 Opened 9 years ago Updated 2 years ago

Give a warning when a copy-constructor/assignment operator reimplements the default ones.

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

defect

Tracking

(Not tracked)

People

(Reporter: jrmuizel, Unassigned)

References

Details

Code should either use '= default' or just use the default one. Manually coding it is prone to bugs.
What would you want to catch for a re-implementation? Initialization of every element to the element from the other type? Should a sequence of assignments in the body be handled as well? How about the ordering?

Here's a few of my immediate thoughts on this:

/* Obviously (I think) this should be caught */
class F {
  int i;
public:
  F(const F& o) : i(o.i) {} // Catch this
};

/* Some examples which could technically change if the default is used... */
class F {
  int i;
public:
  F(const F& o) {
    i = o.i; // Catch this too? Technically uses operator= rather than the copy constructor, so it could be different...
  }
};

class F {
  A a;
  B b;
public:
  F(const F& o) {
    b = o.b; // This not only uses operator=, but also initializes in a different order, should this be caught?
    a = o.a;
  }
};

I'm sure that there are other things which I didn't immediately think of, but these are questions which I think should be answered.
I think the answers to these questions might depend on what kind of code ends up giving warnings. The code that I saw that inspired this bug was using the assignment syntax, so my gut would be to catch that.

I think we may need to iterate on the semantics though.
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.