[PATCH] D19201: [clang-tidy] misc-throw-with-noexcept
Piotr Padlewski via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 1 14:25:33 PDT 2016
Prazek added inline comments.
================
Comment at: clang-tidy/misc/ThrowWithNoexceptCheck.cpp:25
@@ +24,3 @@
+ Finder->addMatcher(
+ cxxThrowExpr(stmt(hasAncestor(functionDecl(isNoThrow()).bind("func"))))
+ .bind("throw"),
----------------
aaron.ballman wrote:
> Prazek wrote:
> > you can use forFunction instead of hasAncestor(functionDecl(
> > cxxThrowExpr(stmt(forFunction(isNoThrow() or cxxThrowExpr(stmt(forFunction(functionDecl(isNoThrow())))
> > you can even try to remove stmt.
> >
> >
> > Also add test case
> >
> > void getFunction() noexcept {
> > struct X {
> > static void inner()
> > {
> > throw 42;
> > }
> > };
> > }
> >
> Hmm, I wonder if it's trivial enough to filter out throw statements that are inside a try block scope (even without checking the expression and catch block types)?
unless(hasAncestor(cxxTryStmt())) should do the work for almost all cases.
Maybe even something like this to catch only valid try blocks
cxxThrowExpr(stmt(forFunction(functionDecl(isNoThrow()).bind("func"))),
unless(hasAncestor(cxxTryStmt().bind("try"), forFunction(hasBody(hasDescendant(equalsBoundNode("try")))))
+ it should check that the throw is not in CXXCatchStmt (unless it is in another try block).
Repository:
rL LLVM
http://reviews.llvm.org/D19201
More information about the cfe-commits
mailing list