On Mon, Aug 24, 2015 at 6:29 PM, Richard Smith <rich...@metafoo.co.uk> wrote: > On Mon, Aug 24, 2015 at 3:23 PM, Aaron Ballman <aaron.ball...@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.
Are you thinking the check would likely in BuildMemberReferenceExpr() and I would just have to look at the current scope to determine whether it's a function-try-block catch handler? When I looked into doing a frontend warning for this, I seemed to struggle with figuring out specifically that I was in the catch handler of a function-try-block of a constructor or destructor. ~Aaron > >> >> 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 >> > _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits