summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compilerplugins/clang/datamembershadow.cxx157
-rw-r--r--compilerplugins/clang/test/datamembershadow.cxx19
-rw-r--r--sc/source/ui/vba/vbanames.cxx3
-rw-r--r--sc/source/ui/vba/vbatextboxshape.cxx1
-rw-r--r--sc/source/ui/vba/vbatextboxshape.hxx1
-rw-r--r--sd/inc/sdundo.hxx3
-rw-r--r--sd/source/core/annotations/Annotation.cxx1
-rw-r--r--sd/source/ui/inc/unmodpg.hxx4
-rw-r--r--sd/source/ui/view/unmodpg.cxx7
-rw-r--r--solenv/CompilerTest_compilerplugins_clang.mk1
10 files changed, 181 insertions, 16 deletions
diff --git a/compilerplugins/clang/datamembershadow.cxx b/compilerplugins/clang/datamembershadow.cxx
new file mode 100644
index 000000000000..a1d4528a2058
--- /dev/null
+++ b/compilerplugins/clang/datamembershadow.cxx
@@ -0,0 +1,157 @@
+/* -*- 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/.
+ */
+
+#include <string>
+#include <iostream>
+#include <map>
+#include <set>
+
+#include "plugin.hxx"
+#include "clang/AST/CXXInheritance.h"
+
+/**
+ * Check for data member being shadowed.
+ *
+ * @TODO check for any members in superclass hierarchy with duplicate names,
+ * more specific names will make the code easier to read
+ */
+namespace
+{
+
+class DataMemberShadow:
+ public RecursiveASTVisitor<DataMemberShadow>, public loplugin::Plugin
+{
+public:
+ explicit DataMemberShadow(InstantiationData const & data): Plugin(data) {}
+
+ virtual void run() override {
+ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
+ }
+
+ bool VisitFieldDecl(FieldDecl const *);
+};
+
+bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl)
+{
+ if (ignoreLocation(fieldDecl)) {
+ return true;
+ }
+ StringRef aFileName = compiler.getSourceManager().getFilename(
+ compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart()));
+
+ // FIXME complex stuff to fix later
+
+ if (aFileName == SRCDIR "/connectivity/source/inc/calc/CTable.hxx")
+ return true;
+ if (aFileName.startswith(SRCDIR "/chart2/source/"))
+ return true;
+ if (aFileName == SRCDIR "/cppcanvas/source/mtfrenderer/emfplus.cxx")
+ return true;
+ if (aFileName == SRCDIR "/cui/source/customize/eventdlg.hxx")
+ return true;
+ if (aFileName == SRCDIR "/include/sfx2/recentdocsview.hxx")
+ return true;
+ if (aFileName == SRCDIR "/include/sfx2/templatelocalview.hxx")
+ return true;
+ if (aFileName == SRCDIR "/filter/source/graphicfilter/idxf/dxfentrd.hxx")
+ return true;
+ if (aFileName == SRCDIR "/framework/source/uielement/popuptoolbarcontroller.cxx")
+ return true;
+ if (aFileName == SRCDIR "/lotuswordpro/source/filter/xfilter/xfcellstyle.hxx")
+ return true;
+ if (aFileName == SRCDIR "/lotuswordpro/source/filter/xfilter/xfdrawobj.hxx")
+ return true;
+ if (aFileName == SRCDIR "/sc/source/ui/vba/vbastyles.hxx")
+ return true;
+ if (aFileName == SRCDIR "/sd/inc/Outliner.hxx")
+ return true;
+ if (aFileName == SRCDIR "/sd/source/ui/annotations/annotationtag.cxx")
+ return true;
+ if (aFileName == SRCDIR "/sd/source/ui/inc/FrameView.hxx"
+ || aFileName == SRCDIR "/sd/source/filter/ppt/../../ui/inc/FrameView.hxx")
+ return true;
+ if (aFileName == SRCDIR "/sd/source/ui/inc/unopage.hxx")
+ return true;
+ if (aFileName == SRCDIR "/sd/source/ui/view/viewoverlaymanager.cxx")
+ return true;
+ if (aFileName == SRCDIR "/sdext/source/presenter/PresenterSpritePane.hxx")
+ return true;
+ if (aFileName == SRCDIR "/store/source/stortree.hxx"
+ || aFileName == SRCDIR "/store/source/stordata.hxx")
+ return true;
+ if (aFileName == SRCDIR "/svx/source/table/cell.hxx"
+ || aFileName == SRCDIR "/svx/source/unodraw/../table/cell.hxx"
+ || aFileName == SRCDIR "/svx/source/accessibility/../table/cell.hxx")
+ return true;
+ if (aFileName == SRCDIR "/sw/source/uibase/inc/dbtree.hxx")
+ return true;
+ if (aFileName == SRCDIR "/vcl/unx/generic/print/genpspgraphics.cxx")
+ return true;
+ if (aFileName == SRCDIR "/xmloff/source/draw/ximplink.hxx")
+ return true;
+
+ const CXXRecordDecl* parentCXXRecordDecl = dyn_cast<CXXRecordDecl>(fieldDecl->getParent());
+ if (!parentCXXRecordDecl) {
+ return true;
+ }
+
+ fieldDecl = fieldDecl->getCanonicalDecl();
+
+#if CLANG_VERSION >= 30800
+
+ auto BaseMatchesCallback = [&](const CXXBaseSpecifier *cxxBaseSpecifier, CXXBasePath& Paths)
+ {
+ if (!cxxBaseSpecifier->getType().getTypePtr())
+ return false;
+ const CXXRecordDecl* baseCXXRecordDecl = cxxBaseSpecifier->getType()->getAsCXXRecordDecl();
+ if (!baseCXXRecordDecl)
+ return false;
+ if (baseCXXRecordDecl->isInvalidDecl())
+ return false;
+ for (const FieldDecl* baseFieldDecl : baseCXXRecordDecl->fields())
+ {
+ if (baseFieldDecl->getAccess() == AS_private
+ || !baseFieldDecl->getDeclName().isIdentifier()
+ || fieldDecl->getName() != baseFieldDecl->getName()) {
+ continue;
+ }
+ std::string sPath;
+ for (CXXBasePathElement const & pathElement : Paths) {
+ if (!sPath.empty()) {
+ sPath += "->";
+ }
+ sPath += pathElement.Class->getNameAsString();
+ }
+ sPath += "->";
+ sPath += baseCXXRecordDecl->getNameAsString();
+ report(DiagnosticsEngine::Warning,
+ "data member %0 is shadowing member in superclass, through inheritance path %1",
+ fieldDecl->getLocStart())
+ << fieldDecl->getName()
+ << sPath
+ << fieldDecl->getSourceRange();
+ report(DiagnosticsEngine::Note,
+ "superclass member here",
+ baseFieldDecl->getLocStart())
+ << baseFieldDecl->getSourceRange();
+ }
+ return false;
+ };
+
+ CXXBasePaths aPaths;
+ parentCXXRecordDecl->lookupInBases(BaseMatchesCallback, aPaths);
+#endif
+ return true;
+}
+
+loplugin::Plugin::Registration< DataMemberShadow > X("datamembershadow", true);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/compilerplugins/clang/test/datamembershadow.cxx b/compilerplugins/clang/test/datamembershadow.cxx
new file mode 100644
index 000000000000..663750a0c22d
--- /dev/null
+++ b/compilerplugins/clang/test/datamembershadow.cxx
@@ -0,0 +1,19 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+
+struct Bar {
+ int x; // expected-note {{superclass member here [loplugin:datamembershadow]}}
+};
+
+struct Foo : public Bar {
+ int x; // expected-error {{data member x is shadowing member in superclass, through inheritance path Foo->Bar [loplugin:datamembershadow]}}
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sc/source/ui/vba/vbanames.cxx b/sc/source/ui/vba/vbanames.cxx
index b30ebe364267..49e9b0d182fb 100644
--- a/sc/source/ui/vba/vbanames.cxx
+++ b/sc/source/ui/vba/vbanames.cxx
@@ -41,10 +41,9 @@ using namespace ::com::sun::star;
class NamesEnumeration : public EnumerationHelperImpl
{
uno::Reference< frame::XModel > m_xModel;
- uno::WeakReference< XHelperInterface > m_xParent;
uno::Reference< sheet::XNamedRanges > m_xNames;
public:
- NamesEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< frame::XModel >& xModel , const uno::Reference< sheet::XNamedRanges >& xNames ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), m_xModel( xModel ), m_xParent( xParent ), m_xNames( xNames ) {}
+ NamesEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< frame::XModel >& xModel , const uno::Reference< sheet::XNamedRanges >& xNames ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), m_xModel( xModel ), m_xNames( xNames ) {}
virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) override
{
diff --git a/sc/source/ui/vba/vbatextboxshape.cxx b/sc/source/ui/vba/vbatextboxshape.cxx
index f3f1c7e7221d..f0e84e716ed1 100644
--- a/sc/source/ui/vba/vbatextboxshape.cxx
+++ b/sc/source/ui/vba/vbatextboxshape.cxx
@@ -28,7 +28,6 @@ using namespace ooo::vba;
ScVbaTextBoxShape::ScVbaTextBoxShape( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XShapes >& xShapes, const uno::Reference< frame::XModel >& xModel ) : TextBoxShapeImpl_BASE( uno::Reference< XHelperInterface >(), xContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape ) )
{
m_xTextRange.set( xShape , uno::UNO_QUERY_THROW );
- m_xModel.set( xModel );
}
OUString SAL_CALL
diff --git a/sc/source/ui/vba/vbatextboxshape.hxx b/sc/source/ui/vba/vbatextboxshape.hxx
index f6616e1842a1..2e762429ac76 100644
--- a/sc/source/ui/vba/vbatextboxshape.hxx
+++ b/sc/source/ui/vba/vbatextboxshape.hxx
@@ -30,7 +30,6 @@ typedef cppu::ImplInheritanceHelper< ScVbaShape, ov::msforms::XTextBoxShape > Te
class ScVbaTextBoxShape : public TextBoxShapeImpl_BASE
{
css::uno::Reference< css::text::XTextRange > m_xTextRange;
- css::uno::Reference< css::frame::XModel > m_xModel;
public:
ScVbaTextBoxShape( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::drawing::XShapes >& xShapes, const css::uno::Reference< css::frame::XModel >& xModel );
diff --git a/sd/inc/sdundo.hxx b/sd/inc/sdundo.hxx
index c7041399daac..fa2d06ee8cd6 100644
--- a/sd/inc/sdundo.hxx
+++ b/sd/inc/sdundo.hxx
@@ -39,8 +39,9 @@ public:
protected:
SdDrawDocument* mpDoc;
- OUString maComment;
sal_Int32 mnViewShellId;
+private:
+ OUString maComment;
};
#endif // INCLUDED_SD_INC_SDUNDO_HXX
diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx
index 52e999579e19..88af7562d06a 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -100,7 +100,6 @@ private:
virtual void SAL_CALL disposing() override;
SdPage* mpPage;
- mutable ::osl::Mutex m_aMutex;
RealPoint2D m_Position;
RealSize2D m_Size;
OUString m_Author;
diff --git a/sd/source/ui/inc/unmodpg.hxx b/sd/source/ui/inc/unmodpg.hxx
index c48482a00cc0..664740675319 100644
--- a/sd/source/ui/inc/unmodpg.hxx
+++ b/sd/source/ui/inc/unmodpg.hxx
@@ -38,8 +38,6 @@ class ModifyPageUndoAction : public SdUndoAction
bool mbOldBckgrndObjsVisible;
bool mbNewBckgrndObjsVisible;
- OUString maComment;
-
public:
ModifyPageUndoAction(
SdDrawDocument* pTheDoc,
@@ -52,8 +50,6 @@ public:
virtual ~ModifyPageUndoAction() override;
virtual void Undo() override;
virtual void Redo() override;
-
- virtual OUString GetComment() const override;
};
class RenameLayoutTemplateUndoAction : public SdUndoAction
diff --git a/sd/source/ui/view/unmodpg.cxx b/sd/source/ui/view/unmodpg.cxx
index 7da13920730f..ac3176c2887f 100644
--- a/sd/source/ui/view/unmodpg.cxx
+++ b/sd/source/ui/view/unmodpg.cxx
@@ -70,7 +70,7 @@ ModifyPageUndoAction::ModifyPageUndoAction(
mbOldBckgrndObjsVisible = false;
}
- maComment = SD_RESSTR(STR_UNDO_MODIFY_PAGE);
+ SetComment( SD_RESSTR(STR_UNDO_MODIFY_PAGE) );
}
void ModifyPageUndoAction::Undo()
@@ -163,11 +163,6 @@ ModifyPageUndoAction::~ModifyPageUndoAction()
{
}
-OUString ModifyPageUndoAction::GetComment() const
-{
- return maComment;
-}
-
RenameLayoutTemplateUndoAction::RenameLayoutTemplateUndoAction(
SdDrawDocument* pDocument,
const OUString& rOldLayoutName,
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
index b0ed91699ac8..ae1a07f0245e 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -12,6 +12,7 @@ $(eval $(call gb_CompilerTest_CompilerTest,compilerplugins_clang))
$(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/salbool \
compilerplugins/clang/test/finalprotected \
+ compilerplugins/clang/test/datamembershadow \
))
# vim: set noet sw=4 ts=4: