Page MenuHomePhabricator

[analyzer] Support Reinitializes attribute in MisusedMovedObject check
ClosedPublic

Authored by xazax.hun on Oct 8 2018, 6:28 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

xazax.hun created this revision.Oct 8 2018, 6:28 AM
NoQ accepted this revision.Oct 8 2018, 7:09 PM

Yay, these look useful. Is there also an attribute for methods that should never be called on a 'moved-from' object?

This revision is now accepted and ready to land.Oct 8 2018, 7:09 PM
In D52983#1258466, @NoQ wrote:

Yay, these look useful. Is there also an attribute for methods that should never be called on a 'moved-from' object?

I do not know about such attribute, but once contracts are implemented and wide-spread, a precondition on a method/function is a strong suggestion that it should not be used on a moved-from object.

This revision was automatically updated to reflect the committed changes.
NoQ added a comment.Oct 9 2018, 1:07 PM
In D52983#1258466, @NoQ wrote:

Yay, these look useful. Is there also an attribute for methods that should never be called on a 'moved-from' object?

I do not know about such attribute, but once contracts are implemented and wide-spread, a precondition on a method/function is a strong suggestion that it should not be used on a moved-from object.

Well, that actually sounds like a pretty good heuristic, as long as we know that a moved-from object cannot reliably satisfy these contracts. In other words, it'll probably be fine for most library classes, but my concern is that the more contracts do we document this way, the more false positives would we have, which is not a healthy correlation. Like, for example, if we add a contract "the object is in a consistent state" to all methods of an STL object, eg. something like this->_length == strlen(this->_buf) for std::string methods, it might be a valid contract, but all moved-from objects would trivially satisfy it (because they are guaranteed to be in a consistent albeit unspecified state), so we won't be able to all any method at all.