[PATCH] D12945: [PATCH] Add checker for objects that should not be value types

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 17 13:57:38 PDT 2015


aaron.ballman created this revision.
aaron.ballman added reviewers: alexfh, klimek.
aaron.ballman added a subscriber: cfe-commits.

Some object types are not meant to be used as a value type in all circumstances, but the language (mainly C) does not provide facilities for marking these types as noncopyable. For instance, you should never pass a FILE object by value, but only by pointer. This seems to fall into two category of types:

A FILE type should never be declared by value (whether as a local, a field, or a parameter) and such a pointer should never be dereferenced.
Some POSIX types, like pthread_mutex_t can be declared by value as a variable or field, but should not be declared by value as a parameter, and such a pointer should never be dereferenced.

This patch adds a checker (misc-non-copyable-objects, but a better moniker would not make me sad) to catch code that does this accidentally. This corresponds (at least for treatment of FILE) to: https://www.securecoding.cert.org/confluence/display/c/FIO38-C.+Do+not+copy+a+FILE+object

~Aaron

http://reviews.llvm.org/D12945

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/NonCopyableObjects.cpp
  clang-tidy/misc/NonCopyableObjects.h
  test/clang-tidy/misc-non-copyable-objects.c
  test/clang-tidy/misc-non-copyable-objects.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12945.35034.patch
Type: text/x-patch
Size: 9334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150917/b7f8e181/attachment.bin>


More information about the cfe-commits mailing list