Open Bug 1792638 Opened 3 years ago Updated 3 years ago

Cannot update MOZ_KNOWN_LIVE members in move assign operator override

Categories

(Developer Infrastructure :: Source Code Analysis, enhancement, P3)

enhancement

Tracking

(Not tracked)

People

(Reporter: masayuki, Unassigned)

References

Details

class MOZ_STACK_CLASS Foo {
 public:
  Foo(Foo&& aOther) : mContent(std::move(aOther.mContent)) {}  // no problem
  Foo& operator=(Foo&& aOther) {
    mContent = std::move(aOther.mContent);  // error: MOZ_KNOWN_LIVE members can only be modified by constructors and destructors
    return *this;
  }
 private:
  MOZ_KNOWN_LIVE nsCOMPtr<nsIContent> mContent;
};

I'm not sure whether assigning the value in move assign operator causes some troubles or not. However, Foo& operator=(Foo&& aOther) = default works. Therefore, they are not consistent result at least.

FYI: I want to define it for validating the members with MOZ_ASSERT.

The severity field is not set for this bug.
:andi, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bpostelnicu)

This was added by https://phabricator.services.mozilla.com/D146023 maybe let's ask :saschanaz what was the reasoning behind it.

Flags: needinfo?(bpostelnicu) → needinfo?(krosylight)

(I believe Masayuki and I had interaction while adding that.)

The intention was to give some real restriction to MOZ_KNOWN_LIVE rather than just randomly declaring it's "live". It's tricky here since we can't make sure the assign operator never overwrites the existing non-null pointer. I'm not sure what to do here tbh, maybe we can require MOZ_ASSERT(!mContent) in the operator?

Flags: needinfo?(krosylight)

The severity field is not set for this bug.
:andi, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bpostelnicu)
Severity: -- → S3
Type: defect → enhancement
Flags: needinfo?(bpostelnicu)
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.