| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2018 Sergio Martins <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "static-pmf.h" |
| 8 |
#include "QtUtils.h" |
| 9 |
#include "TypeUtils.h" |
| 10 |
|
| 11 |
#include <clang/AST/Decl.h> |
| 12 |
#include <clang/AST/Type.h> |
| 13 |
#include <clang/Basic/LLVM.h> |
| 14 |
#include <llvm/Support/Casting.h> |
| 15 |
|
| 16 |
using namespace clang; |
| 17 |
|
| 18 |
void StaticPmf::VisitDecl(clang::Decl *decl) |
| 19 |
{ |
| 20 |
auto *vardecl = dyn_cast<VarDecl>(decl); |
| 21 |
if (!vardecl || !vardecl->isStaticLocal()) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
const Type *t = clazy::unpealAuto(vardecl->getType()); |
| 26 |
if (!t) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
const auto *memberPointerType = dyn_cast<clang::MemberPointerType>(t); |
| 31 |
if (!memberPointerType || !memberPointerType->isMemberFunctionPointer()) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
auto *record = memberPointerType->getMostRecentCXXRecordDecl(); |
| 36 |
if (!clazy::isQObject(record, m_context->qtNamespace())) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
emitWarning(vardecl, "Static pointer to member has portability issues"); |
| 41 |
} |