File indexing completed on 2024-04-28 05:38:27

0001 /*
0002     SPDX-FileCopyrightText: 2016-2017 Sergio Martins <smartins@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef CLAZY_UNUSED_NON_TRIVIAL_VARIABLE_H
0008 #define CLAZY_UNUSED_NON_TRIVIAL_VARIABLE_H
0009 
0010 #include "checkbase.h"
0011 
0012 #include <string>
0013 #include <vector>
0014 
0015 class ClazyContext;
0016 
0017 namespace clang
0018 {
0019 class Stmt;
0020 class VarDecl;
0021 class CXXRecordDecl;
0022 class QualType;
0023 }
0024 
0025 /**
0026  * Warns about unused Qt value classes.
0027  * Compilers usually only warn when trivial classes are unused and don't emit warnings for non-trivial classes.
0028  * This check has a whitelist of common Qt classes such as containers, QFont, QUrl, etc and warns for those too.
0029  *
0030  * See README-unused-non-trivial-variable.md for more information
0031  */
0032 class UnusedNonTrivialVariable : public CheckBase
0033 {
0034 public:
0035     explicit UnusedNonTrivialVariable(const std::string &name, ClazyContext *context);
0036     void VisitStmt(clang::Stmt *stmt) override;
0037 
0038 private:
0039     void handleVarDecl(clang::VarDecl *varDecl);
0040     bool isInterestingType(clang::QualType t) const;
0041     bool isUninterestingType(const clang::CXXRecordDecl *record) const;
0042     std::vector<std::string> m_userBlacklist;
0043     std::vector<std::string> m_userWhitelist;
0044 };
0045 
0046 #endif