[PATCH] D12301: [PATCH] New checker for UB in handler of a function-try-block

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 24 15:23:27 PDT 2015


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

Per [except.handle]p10, the handler for a constructor or destructor function-try-block cannot refer to a non-static member of the object under construction. This patch adds a new clang-tidy check that warns the user when they've hit this undefined behavior.

Due to how infrequent function-try-blocks appear on constructors and destructors in the wild compared to how often member expressions are encountered, I felt this was more appropriate as a clang-tidy check than as a semantic warning. I was concerned with efficiency of checking whether an arbitrary member expression was referring to the object under construction/destruction within the function-try-block catch handler scope.

This patch corresponds to the CERT secure coding rule ERR53-CPP (https://www.securecoding.cert.org/confluence/display/cplusplus/ERR53-CPP.+Do+not+reference+base+classes+or+class+data+members+in+a+constructor+or+destructor+function-try-block+handler)

http://reviews.llvm.org/D12301

Files:
  clang-tidy/misc/CDtorCatchHandlerCheck.cpp
  clang-tidy/misc/CDtorCatchHandlerCheck.h
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  test/clang-tidy/misc-cdtor-catch-handler.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12301.33012.patch
Type: text/x-patch
Size: 6732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150824/51953f0d/attachment.bin>


More information about the cfe-commits mailing list