[cfe-dev] [Static Analyzer] Rules for enforcing smart-ptr usage?

Fredrik Orderud forderud at gmail.com
Tue Dec 3 12:19:09 PST 2013


It would be nice with rules for enforcing smart-pointer usage in C++. I
guess that this can be achieved by disallowing assignment of the
return-value of "new" to a raw pointer. It would also be possible to
disallow "delete" altogether, but might be a bit indirect.

The return-value of "new" should instead be assigned directly to a
auto_ptr/scoped_ptr/unique_ptr/shared_ptr or other user-defined RAII type.
Hopefully, a rule wouldn't need to depend on a "whitelist" of pre-approved
smart-ptr types.

Smart-ptr enforcement is probably not something that everyone would like to
activate, but it could still be very valuable for avoiding memory &
resource leaks if it was an optional checker.

Could this be possible to implement?

Thanks in advance,
Fredrik Orderud
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131203/a9271204/attachment.html>


More information about the cfe-dev mailing list