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", "")),
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);
.castAs<FunctionProtoTypeLoc>()
.getExceptionSpecRange();
}
+
+ assert(Range.isValid() && "Exception Source Range is invalid.");
+
CharSourceRange CRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Range), *Result.SourceManager,
Result.Context->getLangOpts());
--- /dev/null
+// 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]