[PATCH] D80371: [clang-tidy] Fix potential assert in use-noexcept check

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 24 06:56:04 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c5818dd8cd9: [clang-tidy] Fix potential assert in use-noexcept check (authored by njames93).

Changed prior to commit:
  https://reviews.llvm.org/D80371?vs=265923&id=265924#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80371/new/

https://reviews.llvm.org/D80371

Files:
  clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h
  clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-error.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-error.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-error.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s modernize-use-noexcept %t
+
+// We're not interested in the check issuing a warning here, just making sure
+// clang-tidy doesn't assert.
+undefined_type doesThrow() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: error: unknown type name 'undefined_type' [clang-diagnostic-error]
Index: clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h
+++ clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h
@@ -41,7 +41,7 @@
 
 private:
   const std::string NoexceptMacro;
-  bool UseNoexceptFalse;
+  const bool UseNoexceptFalse;
 };
 
 } // namespace modernize
Index: clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
@@ -16,6 +16,10 @@
 namespace tidy {
 namespace modernize {
 
+namespace {
+AST_MATCHER(NamedDecl, isValid) { return !Node.isInvalidDecl(); }
+} // namespace
+
 UseNoexceptCheck::UseNoexceptCheck(StringRef Name, ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context),
       NoexceptMacro(Options.get("ReplacementString", "")),
@@ -29,20 +33,12 @@
 void UseNoexceptCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
       functionDecl(
-          cxxMethodDecl(
-              hasTypeLoc(loc(functionProtoType(hasDynamicExceptionSpec()))),
-              anyOf(hasOverloadedOperatorName("delete[]"),
-                    hasOverloadedOperatorName("delete"), cxxDestructorDecl()))
-              .bind("del-dtor"))
-          .bind("funcDecl"),
-      this);
-
-  Finder->addMatcher(
-      functionDecl(
+          isValid(),
           hasTypeLoc(loc(functionProtoType(hasDynamicExceptionSpec()))),
-          unless(anyOf(hasOverloadedOperatorName("delete[]"),
-                       hasOverloadedOperatorName("delete"),
-                       cxxDestructorDecl())))
+          optionally(cxxMethodDecl(anyOf(hasAnyOverloadedOperatorName(
+                                             "delete[]", "delete"),
+                                         cxxDestructorDecl()))
+                         .bind("del-dtor")))
           .bind("funcDecl"),
       this);
 
@@ -80,6 +76,9 @@
                   .castAs<FunctionProtoTypeLoc>()
                   .getExceptionSpecRange();
   }
+
+  assert(Range.isValid() && "Exception Source Range is invalid.");
+
   CharSourceRange CRange = Lexer::makeFileCharRange(
       CharSourceRange::getTokenRange(Range), *Result.SourceManager,
       Result.Context->getLangOpts());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80371.265924.patch
Type: text/x-patch
Size: 3020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200524/e6e57c67/attachment-0001.bin>


More information about the cfe-commits mailing list