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

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 24 15:29:08 PDT 2015


On Mon, Aug 24, 2015 at 3:23 PM, Aaron Ballman <aaron.ballman at gmail.com>
wrote:

> 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.
>

Seems like this would be very cheap to check in the case where the object
expression is an implicit or explicit CXXThisExpr. It'd be good to have a
frontend warning for that case.


> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150824/67475bc8/attachment.html>


More information about the cfe-commits mailing list