[clang-tidy] Ignore declarations in bugprone-exception-escape
authorPiotr Zegar <me@piotrzegar.pl>
Sun, 30 Apr 2023 18:22:44 +0000 (18:22 +0000)
committerPiotr Zegar <me@piotrzegar.pl>
Sun, 30 Apr 2023 18:22:44 +0000 (18:22 +0000)
Warnings will now only be printed for function definitions, not declarations

Reviewed By: isuckatcs

Differential Revision: https://reviews.llvm.org/D148462

clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

index 276c46ca9fe90ca4f984870165f0169b166a04e4..635cc2ca05d1200eb5a82cb9135edf820a603731 100644 (file)
@@ -52,7 +52,8 @@ void ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-      functionDecl(anyOf(isNoThrow(), cxxDestructorDecl(),
+      functionDecl(isDefinition(),
+                   anyOf(isNoThrow(), cxxDestructorDecl(),
                          cxxConstructorDecl(isMoveConstructor()),
                          cxxMethodDecl(isMoveAssignmentOperator()),
                          hasName("main"), hasName("swap"),
index 49f880c971a344b8a44864eb7991d75198af23a7..5695d59e89153c53c612237b993c5b54d1028763 100644 (file)
@@ -201,6 +201,10 @@ Changes in existing checks
   <clang-tidy/checks/bugprone/dynamic-static-initializers>` check.
   Global options of the same name should be used instead.
 
+- Improved :doc:`bugprone-exception-escape
+  <clang-tidy/checks/bugprone/exception-escape>` to not emit warnings for
+  forward declarations of functions.
+
 - Improved :doc:`bugprone-fold-init-type
   <clang-tidy/checks/bugprone/fold-init-type>` to handle iterators that do not
   define `value_type` type aliases.
index 142c8b114b7c8a7afda9f0f2b0be8c27f07e8550..78d434854b095fdb007e599486412a37581dbaa2 100644 (file)
@@ -655,7 +655,6 @@ int directly_recursive(int n) noexcept {
 }
 
 int indirectly_recursive(int n) noexcept;
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'indirectly_recursive' which should not throw exceptions
 
 int recursion_helper(int n) {
   indirectly_recursive(n);