/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ #ifndef LO_CLANG_SHARED_PLUGINS
/* what might be more interesting is a warning about subclasses that add members but do not override virtual operator==() - that is easily forgotten and hard to notice.
*/ namespace {
class SfxPoolItem: public loplugin::FilteringPlugin<SfxPoolItem>
{ public: explicit SfxPoolItem(loplugin::InstantiationData const & data): FilteringPlugin(data)
{}
bool isDerivedFromSfxPoolItem(const CXXRecordDecl *decl) { if (!decl) returnfalse; if (loplugin::TypeCheck(decl).Class("SfxPoolItem").GlobalNamespace()) returntrue; if (!decl->hasDefinition()) { returnfalse;
} if (// not sure what hasAnyDependentBases() does, // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() &&
!decl->forallBases(BaseCheckNotSfxPoolItemSubclass)) { returntrue;
} returnfalse;
}
bool isDerivedFromSwMsgPoolItem(const CXXRecordDecl *decl) { if (!decl) returnfalse; if (loplugin::TypeCheck(decl).Class("SwMsgPoolItem").GlobalNamespace()) returntrue; if (!decl->hasDefinition()) { returnfalse;
} if (// not sure what hasAnyDependentBases() does, // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() &&
!decl->forallBases(BaseCheckNotSwMsgPoolItemSubclass)) { returntrue;
} returnfalse;
}
bool endsWith(const std::string& a, const std::string& b) { if (b.size() > a.size()) returnfalse; return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
}
bool SfxPoolItem::VisitCXXRecordDecl(const CXXRecordDecl* decl)
{ if (ignoreLocation(decl)) { returntrue;
} if (!decl->isThisDeclarationADefinition()) { returntrue;
} // check if this class is derived from Window if (!isDerivedFromSfxPoolItem(decl)) { returntrue;
} // the SwMsgPoolItem are some sort of hack to transport down-castable objects to SwClient::Modify(), they're not "real" items if (isDerivedFromSwMsgPoolItem(decl)) { returntrue;
} if (decl->field_begin() == decl->field_end()) { returntrue;
} // the enum types do some weird stuff involving SfxEnumItemInterface auto tc = loplugin::TypeCheck(decl); if (tc.Class("SfxEnumItem").GlobalNamespace() || tc.Class("SfxAllEnumItem").GlobalNamespace()) returntrue;
for (auto it = decl->method_begin(); it != decl->method_end(); ++it) { if ( endsWith((*it)->getQualifiedNameAsString(), "::operator==") ) returntrue;
}
report(
DiagnosticsEngine::Warning, "SfxPoolItem subclass %0 declares new fields, but does not override operator==",
decl->getBeginLoc())
<< decl->getQualifiedNameAsString() << decl->getSourceRange(); returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.