1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
16 // Second-guess that certain private special member function declarations for
17 // which no definition can be found are left undefined to prevent them from
18 // being implicitly declared. Such situations are better expressed by marking
19 // the function as = delete (it e.g. helps compilers determine
20 // whether class members are unused if all of a class's member definitions are
21 // seen in a compilation unit). (Default constructors for classes with multiple
22 // constructors are exempted as they would not be implicitly declared.
23 // Destructors are exempted because it is likely that a destructor is defined
24 // private on purpose.)
28 CXXRecordDecl
const * getClass(CXXMethodDecl
const * decl
) {
29 CXXRecordDecl
const * cls
= dyn_cast
<CXXRecordDecl
>(decl
->getDeclContext());
30 assert(cls
!= nullptr);
35 public loplugin::FilteringPlugin
<DeletedSpecial
>
38 explicit DeletedSpecial(InstantiationData
const & data
): FilteringPlugin(data
) {}
40 virtual void run() override
;
42 bool VisitCXXMethodDecl(CXXMethodDecl
const * decl
);
46 CXXMethodDecl
const * decl
, std::string
const & name
,
47 std::string
const & path
);
50 void DeletedSpecial::run() {
51 if (compiler
.getLangOpts().CPlusPlus
52 && compiler
.getPreprocessor().getIdentifierInfo(
53 "LIBO_INTERNAL_ONLY")->hasMacroDefinition())
55 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
59 bool DeletedSpecial::VisitCXXMethodDecl(CXXMethodDecl
const * decl
) {
60 if (ignoreLocation(decl
) || !decl
->isFirstDecl() || decl
->isDefined()
61 || decl
->isDefaulted() || decl
->getAccess() != AS_private
)
66 if (decl
->isCopyAssignmentOperator()) {
67 if (allowlist(decl
, "ImpGraphic", "vcl/inc/impgraph.hxx")
68 || allowlist(decl
, "SwSubFont", "sw/source/core/inc/swfont.hxx"))
72 desc
= "copy assignment operator";
73 } else if (decl
->isMoveAssignmentOperator()) {
74 desc
= "move assignment operator";
76 CXXConstructorDecl
const * ctor
= dyn_cast
<CXXConstructorDecl
>(decl
);
77 CXXRecordDecl
const * cls
= getClass(decl
);
78 if (ctor
!= nullptr && ctor
->isCopyConstructor()) {
79 if (allowlist(decl
, "ImpGraphic", "vcl/inc/impgraph.hxx")
80 || allowlist(decl
, "SbMethod", "include/basic/sbmeth.hxx")
81 || allowlist(decl
, "ScDBCollection::NamedDBs", "sc/inc/dbdata.hxx")
82 || allowlist(decl
, "ScDrawPage", "sc/inc/drawpage.hxx")
83 || allowlist(decl
, "SmEditSource", "starmath/source/accessibility.hxx")
84 || allowlist(decl
, "SwChartDataSequence", "sw/inc/unochart.hxx")
85 || allowlist(decl
, "SwDPage", "sw/inc/dpage.hxx")
86 || allowlist(decl
, "SwRedlineExtraData_Format", "sw/inc/redline.hxx")
87 || allowlist(decl
, "SwRedlineExtraData_FormattingChanges", "sw/inc/redline.hxx")
88 || allowlist(decl
, "SwTextAPIEditSource", "sw/source/core/inc/textapi.hxx")
89 || allowlist(decl
, "XclImpBiff5Decrypter", "sc/source/filter/inc/xistream.hxx")
90 || allowlist(decl
, "XclImpBiff8Decrypter", "sc/source/filter/inc/xistream.hxx")
91 || allowlist(decl
, "configmgr::LocalizedPropertyNode", "configmgr/source/localizedpropertynode.hxx")
92 || allowlist(decl
, "configmgr::LocalizedValueNode", "configmgr/source/localizedvaluenode.hxx")
93 || allowlist(decl
, "configmgr::PropertyNode", "configmgr/source/propertynode.hxx")
94 || allowlist(decl
, "oox::xls::BiffDecoder_RCF", "sc/source/filter/inc/biffcodec.hxx")
95 || allowlist(decl
, "oox::xls::BiffDecoder_XOR", "sc/source/filter/inc/biffcodec.hxx")
96 || allowlist(decl
, "rptui::OReportPage", "reportdesign/inc/RptPage.hxx"))
100 desc
= "copy constructor";
101 } else if (ctor
!= nullptr && ctor
->isMoveConstructor()) {
102 desc
= "move constructor";
103 } else if (ctor
!= nullptr && ctor
->isDefaultConstructor()
104 && std::distance(cls
->ctor_begin(), cls
->ctor_end()) == 1)
106 if (allowlist(decl
, "AquaA11yFocusListener", "vcl/osx/a11yfocuslistener.hxx")
107 || allowlist(decl
, "DocTemplLocaleHelper", "sfx2/source/doc/doctemplateslocal.hxx")
108 || allowlist(decl
, "ScViewDataTable", "sc/source/filter/excel/../../ui/inc/viewdata.hxx")
109 || allowlist(decl
, "ScViewDataTable", "sc/source/ui/inc/viewdata.hxx")
110 || allowlist(decl
, "SwLineInfo", "sw/source/core/text/inftxt.hxx")
111 || allowlist(decl
, "XRenderPeer", "vcl/unx/generic/gdi/xrender_peer.hxx")
112 || allowlist(decl
, "desktop::DispatchWatcher", "desktop/source/app/dispatchwatcher.hxx")
113 || allowlist(decl
, "desktop::RequestHandler", "desktop/source/app/officeipcthread.hxx")
114 || allowlist(decl
, "desktop::RequestHandler", "desktop/source/lib/../app/officeipcthread.hxx")
115 || allowlist(decl
, "sd::DiscoveryService", "sd/source/ui/remotecontrol/DiscoveryService.hxx")
116 || allowlist(decl
, "sd::IconCache", "sd/source/ui/inc/tools/IconCache.hxx")
117 || allowlist(decl
, "sd::RemoteServer", "sd/source/ui/inc/RemoteServer.hxx")
118 || allowlist(decl
, "sd::slidesorter::cache::PageCacheManager", "sd/source/ui/slidesorter/inc/cache/SlsPageCacheManager.hxx")
119 || allowlist(decl
, "framework::CommandInfoProvider", "include/framework/commandinfoprovider.hxx")
120 || allowlist(decl
, "vcl::SettingsConfigItem", "vcl/inc/configsettings.hxx")
121 || allowlist(decl
, "writerfilter::ooxml::OOXMLFactory", "writerfilter/source/ooxml/OOXMLFactory.hxx"))
125 desc
= "default constructor";
131 DiagnosticsEngine::Warning
,
132 ("private %0 is not defined at least in this compilation unit, maybe it"
133 " should be marked as deleted?"),
135 << desc
<< decl
->getSourceRange();
139 bool DeletedSpecial::allowlist(
140 CXXMethodDecl
const * decl
, std::string
const & name
,
141 std::string
const & path
)
143 return getClass(decl
)->getQualifiedNameAsString() == name
144 && (getFilenameOfLocation(
145 compiler
.getSourceManager().getSpellingLoc(decl
->getLocation()))
146 == SRCDIR
"/" + path
);
149 loplugin::Plugin::Registration
<DeletedSpecial
> X("deletedspecial", true);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */