diff options
author | Sergio Martins <smartins@kde.org> | 2019-01-11 20:02:52 +0000 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2019-01-11 20:02:52 +0000 |
commit | 07a54ffa240a9727095dc956b91987a08ddbc11a (patch) | |
tree | 5046b58da9c73578925b0b618b53369438fb17fd | |
parent | efa0980c46063fe2426042df462b35e8b404110e (diff) |
Try to fix build with clang trunk
I don't have trunk, but this should work.
Maybe some header missing. Reporter to test.
CCBUG: 403083
-rw-r--r-- | src/SourceCompatibilityHelpers.h | 23 | ||||
-rw-r--r-- | src/checks/manuallevel/qrequiredresult-candidates.cpp | 2 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/SourceCompatibilityHelpers.h b/src/SourceCompatibilityHelpers.h index 9b1fc772..440b1226 100644 --- a/src/SourceCompatibilityHelpers.h +++ b/src/SourceCompatibilityHelpers.h @@ -25,6 +25,8 @@ #include <clang/Basic/SourceLocation.h> #include <clang/Basic/SourceManager.h> +#include <clang/AST/Decl.h> +#include <clang/AST/Expr.h> namespace clazy { @@ -58,6 +60,27 @@ inline clang::CharSourceRange getImmediateExpansionRange(clang::SourceLocation m #endif } +inline bool hasUnusedResultAttr(clang::FunctionDecl *func) +{ +#if LLVM_VERSION_MAJOR >= 8 + auto RetType = func->getReturnType(); + if (const auto *Ret = RetType->getAsRecordDecl()) { + if (const auto *R = Ret->getAttr<clang::WarnUnusedResultAttr>()) + return R != nullptr; + } else if (const auto *ET = RetType->getAs<clang::EnumType>()) { + if (const EnumDecl *ED = ET->getDecl()) { + if (const auto *R = ED->getAttr<clang::WarnUnusedResultAttr>()) + return R != nullptr; + } + } + return clang::getAttr<clang::WarnUnusedResultAttr>() != nullptr; +#else + return func->hasUnusedResultAttr(); +#endif + +} + + } #endif diff --git a/src/checks/manuallevel/qrequiredresult-candidates.cpp b/src/checks/manuallevel/qrequiredresult-candidates.cpp index 40501a38..912dbaa0 100644 --- a/src/checks/manuallevel/qrequiredresult-candidates.cpp +++ b/src/checks/manuallevel/qrequiredresult-candidates.cpp @@ -45,7 +45,7 @@ void QRequiredResultCandidates::VisitDecl(clang::Decl *decl) if (method->isThisDeclarationADefinition() && !method->hasInlineBody()) // Don't warn twice return; - if (method->hasUnusedResultAttr()) // Also catches nodiscard + if (clazy::hasUnusedResultAttr(method)) // Also catches nodiscard return; if (method->getAccess() == AS_private) // We're only interested on our public API |