diff --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h --- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h @@ -41,7 +41,7 @@ private: const std::string NoexceptMacro; - bool UseNoexceptFalse; + const bool UseNoexceptFalse; }; } // namespace modernize diff --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp +++ b/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() .getExceptionSpecRange(); } + + assert(Range.isValid() && "Exception Source Range is invalid."); + CharSourceRange CRange = Lexer::makeFileCharRange( CharSourceRange::getTokenRange(Range), *Result.SourceManager, Result.Context->getLangOpts());