<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 24, 2015 at 3:23 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron.ballman@gmail.com" target="_blank">aaron.ballman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">aaron.ballman created this revision.<br>
aaron.ballman added reviewers: alexfh, rsmith.<br>
aaron.ballman added a subscriber: cfe-commits.<br>
<br>
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.<br>
<br>
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.<br></blockquote><div><br></div><div>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.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This patch corresponds to the CERT secure coding rule ERR53-CPP (<a href="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" rel="noreferrer" target="_blank">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</a>)<br>
<br>
<a href="http://reviews.llvm.org/D12301" rel="noreferrer" target="_blank">http://reviews.llvm.org/D12301</a><br>
<br>
Files:<br>
  clang-tidy/misc/CDtorCatchHandlerCheck.cpp<br>
  clang-tidy/misc/CDtorCatchHandlerCheck.h<br>
  clang-tidy/misc/CMakeLists.txt<br>
  clang-tidy/misc/MiscTidyModule.cpp<br>
  test/clang-tidy/misc-cdtor-catch-handler.cpp<br>
<br>
</blockquote></div><br></div></div>