File indexing completed on 2024-05-19 05:41:42

0001 /*
0002     SPDX-FileCopyrightText: 2018 Sergio Martins <smartins@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "static-pmf.h"
0008 #include "QtUtils.h"
0009 #include "TypeUtils.h"
0010 
0011 #include <clang/AST/Decl.h>
0012 #include <clang/AST/Type.h>
0013 #include <clang/Basic/LLVM.h>
0014 #include <llvm/Support/Casting.h>
0015 
0016 class ClazyContext;
0017 namespace clang
0018 {
0019 class Decl;
0020 } // namespace clang
0021 
0022 using namespace clang;
0023 
0024 StaticPmf::StaticPmf(const std::string &name, ClazyContext *context)
0025     : CheckBase(name, context)
0026 {
0027 }
0028 
0029 void StaticPmf::VisitDecl(clang::Decl *decl)
0030 {
0031     auto *vardecl = dyn_cast<VarDecl>(decl);
0032     if (!vardecl || !vardecl->isStaticLocal()) {
0033         return;
0034     }
0035 
0036     const Type *t = clazy::unpealAuto(vardecl->getType());
0037     if (!t) {
0038         return;
0039     }
0040 
0041     const auto *memberPointerType = dyn_cast<clang::MemberPointerType>(t);
0042     if (!memberPointerType || !memberPointerType->isMemberFunctionPointer()) {
0043         return;
0044     }
0045 
0046     auto *record = memberPointerType->getMostRecentCXXRecordDecl();
0047     if (!clazy::isQObject(record)) {
0048         return;
0049     }
0050 
0051     emitWarning(vardecl, "Static pointer to member has portability issues");
0052 }