bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / store / deadclass.cxx
blobf055d6de283031e5a84d91a8d7b1de74fdd8c1a2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "plugin.hxx"
12 namespace {
14 class DeadClass:
15 public loplugin::FilteringPlugin<DeadClass>
17 public:
18 explicit DeadClass(InstantiationData const & data): FilteringPlugin(data) {}
20 void run() override;
22 bool VisitCXXRecordDecl(CXXRecordDecl const *);
25 void DeadClass::run() {
26 if (compiler.getLangOpts().CPlusPlus) {
27 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
31 bool DeadClass::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
32 if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition())
33 return true;
34 if (decl->needsImplicitDefaultConstructor())
35 return true;
36 if (decl->getDescribedClassTemplate())
37 return true;
38 if (isa<ClassTemplateSpecializationDecl>(decl))
39 return true;
40 int otherCnt = 0;
41 int copyMoveCnt = 0;
42 for (auto i = decl->ctor_begin(); i != decl->ctor_end(); ++i) {
43 if (!i->isUserProvided())
44 continue;
45 if (i->isCopyOrMoveConstructor())
46 copyMoveCnt++;
47 else
48 otherCnt++;
50 if (otherCnt == 0 && copyMoveCnt > 0)
52 report(
53 DiagnosticsEngine::Warning,
54 "class has only copy/move constructors, must be dead",
55 decl->getLocStart())
56 << decl->getSourceRange();
57 for (auto i = decl->ctor_begin(); i != decl->ctor_end(); ++i) {
58 if (i->isDeleted())
59 continue;
62 return true;
65 loplugin::Plugin::Registration<DeadClass> X("deadclass");
69 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */