[PATCH] D53187: [clang-tidy] Optimize query in bugprone-exception-escape
Balogh, Ádám via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 13 03:36:51 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344444: [clang-tidy] Optimize query in bugprone-exception-escape (authored by baloghadamsoftware, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D53187?vs=169552&id=169557#toc
Repository:
rL LLVM
https://reviews.llvm.org/D53187
Files:
clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-exception-escape.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-exception-escape.cpp
Index: clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -190,12 +190,12 @@
return;
Finder->addMatcher(
- functionDecl(allOf(throws(unless(isIgnored(IgnoredExceptions))),
- anyOf(isNoThrow(), cxxDestructorDecl(),
+ functionDecl(allOf(anyOf(isNoThrow(), cxxDestructorDecl(),
cxxConstructorDecl(isMoveConstructor()),
cxxMethodDecl(isMoveAssignmentOperator()),
hasName("main"), hasName("swap"),
- isEnabled(FunctionsThatShouldNotThrow))))
+ isEnabled(FunctionsThatShouldNotThrow)),
+ throws(unless(isIgnored(IgnoredExceptions)))))
.bind("thrower"),
this);
}
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-exception-escape.rst
===================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-exception-escape.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-exception-escape.rst
@@ -21,6 +21,8 @@
operations are also used to create move operations. A throwing ``main()``
function also results in unexpected termination.
+WARNING! This check may be expensive on large source files.
+
Options
-------
Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-exception-escape.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-exception-escape.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-exception-escape.cpp
@@ -258,6 +258,31 @@
throw ignored1();
}
+void thrower(int n) {
+ throw n;
+}
+
+int directly_recursive(int n) noexcept {
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in funcion 'directly_recursive' which should not throw exceptions
+ if (n == 0)
+ thrower(n);
+ return directly_recursive(n);
+}
+
+int indirectly_recursive(int n) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in functin 'indirectly_recursive' which should not throw exceptions
+
+int recursion_helper(int n) {
+ indirectly_recursive(n);
+}
+
+int indirectly_recursive(int n) noexcept {
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in funcion 'indirectly_recursive' which should not throw exceptions
+ if (n == 0)
+ thrower(n);
+ return recursion_helper(n);
+}
+
int main() {
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'main' which should not throw exceptions
throw 1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53187.169557.patch
Type: text/x-patch
Size: 2864 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181013/a871de8d/attachment.bin>
More information about the cfe-commits
mailing list