diff --git a/checks/nonpodstatic.cpp b/checks/nonpodstatic.cpp index e5414b9..dfe69fb 100644 --- a/checks/nonpodstatic.cpp +++ b/checks/nonpodstatic.cpp @@ -1,88 +1,88 @@ /* This file is part of the clang-lazy static checker. Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Sérgio Martins Copyright (C) 2015 Sergio Martins This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "nonpodstatic.h" #include "Utils.h" #include "StringUtils.h" #include "checkmanager.h" #include #include using namespace clang; using namespace std; static bool shouldIgnoreType(const std::string &name, const clang::CompilerInstance &ci) { // Q_GLOBAL_STATIC and such static vector blacklist = {"Holder", "AFUNC", "QLoggingCategory"}; return find(blacklist.cbegin(), blacklist.cend(), name) != blacklist.cend(); } NonPodStatic::NonPodStatic(const std::string &name, const clang::CompilerInstance &ci) : CheckBase(name, ci) { } void NonPodStatic::VisitDecl(clang::Decl *decl) { auto varDecl = dyn_cast(decl); if (!varDecl || varDecl->isConstexpr() || varDecl->isExternallyVisible() || !varDecl->isFileVarDecl()) return; StorageDuration sd = varDecl->getStorageDuration(); if (sd != StorageDuration::SD_Static) return; QualType qt = varDecl->getType(); const bool isTrivial = qt.isTrivialType(m_ci.getASTContext()); if (isTrivial) return; const Type *t = qt.getTypePtrOrNull(); if (!t || !t->getAsCXXRecordDecl() || t->getAsCXXRecordDecl()->isLiteral()) return; const SourceLocation declStart = decl->getLocStart(); auto macroName = Lexer::getImmediateMacroName(declStart, m_ci.getSourceManager(), m_ci.getLangOpts()); if (stringStartsWith(macroName, "Q_CONSTRUCTOR_FUNCTION")) // Don't warn on these return; const string className = t->getAsCXXRecordDecl()->getName(); if (!shouldIgnoreType(className, m_ci)) { std::string error = "non-POD static (" + className + ")"; emitWarning(declStart, error.c_str()); } } std::vector NonPodStatic::filesToIgnore() const { - return {"main.cpp", "qrc_"}; + return {"main.cpp", "qrc_", "qdbusxml2cpp"}; } REGISTER_CHECK_WITH_FLAGS("non-pod-global-static", NonPodStatic, CheckLevel1)