Cannot update MOZ_KNOWN_LIVE members in move assign operator override
Categories
(Developer Infrastructure :: Source Code Analysis, enhancement, P3)
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.
Reporter | ||
Comment 1•3 years ago
|
||
FYI: I want to define it for validating the members with MOZ_ASSERT
.
Comment 2•3 years ago
|
||
The severity field is not set for this bug.
:andi, could you have a look please?
For more information, please visit auto_nag documentation.
Comment 3•3 years ago
|
||
This was added by https://phabricator.services.mozilla.com/D146023 maybe let's ask :saschanaz what was the reasoning behind it.
Comment 4•3 years ago
|
||
(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?
Comment 5•3 years ago
|
||
The severity field is not set for this bug.
:andi, could you have a look please?
For more information, please visit auto_nag documentation.
Updated•3 years ago
|
Description
•