Skip to content

Commit

Permalink
fix crash in nodiscard check
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier-varez committed Jul 29, 2022
1 parent 9526379 commit 93f532f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions clang-tools-extra/clang-tidy/daedalean/UseNodiscardCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ AST_MATCHER(FunctionDecl, isDefinitionOrInline) {
return !(Node.isThisDeclarationADefinition() && Node.isOutOfLine());
}

AST_MATCHER(FunctionDecl, isBuiltinFunction) {
return Node.getBuiltinID() != 0;
}

AST_MATCHER(CXXMethodDecl, isOverloadedPredecrementOperator) {
// Don't put ``[[nodiscard]]`` in front of predecrement operators that return
// a reference.
Expand Down Expand Up @@ -80,13 +84,15 @@ void UseNodiscardCheck::registerMatchers(MatchFinder *Finder) {
isNoReturn(), cxxDeductionGuideDecl(),
isOverloadedAssignmentOperator(),
isOverloadedPreincrementOperator(),
isBuiltinFunction(),
isOverloadedPredecrementOperator()))))
.bind("no_discard"),
this);
Finder->addMatcher(
functionDecl(allOf(isNotMethod(), isDefinitionOrInline(),
unless(anyOf(returns(voidType()), isNoReturn(),
cxxDeductionGuideDecl()))))
functionDecl(
allOf(isNotMethod(), isDefinitionOrInline(),
unless(anyOf(returns(voidType()), isNoReturn(),
isBuiltinFunction(), cxxDeductionGuideDecl()))))
.bind("no_discard_func"),
this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,7 @@ template <typename T>
[[nodiscard]] typename T::value f3(T &) noexcept;

[[nodiscard]] bool f4();

[[nodiscard]] bool callBuiltin() {
return __builtin_isinf(0.0) != 0;
}

0 comments on commit 93f532f

Please sign in to comment.