summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test/unoaggregation.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2023-01-20 15:21:15 +0100
committerStephan Bergmann <sbergman@redhat.com>2023-01-20 20:26:36 +0000
commit022085ece4149a31d22cc85028e71cd2340409ed (patch)
tree2a06d092c2212d74d0f3967716f238ad1b7bcd8d /compilerplugins/clang/test/unoaggregation.cxx
parentc6cf80af60d23fc52502f88f24dc23ad85462e77 (diff)
New loplugin:unoaggregation
"Find classes that derive from css::uno::XAggregation, but which implement queryInterface in violation of the protocol laid out in the documentation at udkapi/com/sun/star/uno/XAggregation.idl (which implies that such a class either doesn't actually make use of the deprecated XAggregation mechanism, which should thus be removed from that class hierarchy, or that its implementation of queryInterface needs to be fixed)." (compilerplugins/clang/unoaggregation.cxx) The basesHaveOnlyPureQueryInterface check in compilerplugins/clang/unoaggregation.cxx is "a crude approximation (but which appears to work OK)" to filter out any queryInterface base implementations of class hierarchies supporting XAggregation (i.e., cppu::OWeakAggObject::queryInterface). It only fails for the odd ChartDocumentWrapper::queryInterface, which manually implements the XAggregation functionality rather than (indirectly) deriving from OWeakAggObject. But changing that manual implementation looks tricky, so leave that alone for now and add a loplugin warning suppression there, and leave proper clean up for later. Change-Id: Ib16e26237bd703e60b0d9cb7134cb39840842d54 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145912 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/test/unoaggregation.cxx')
-rw-r--r--compilerplugins/clang/test/unoaggregation.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/unoaggregation.cxx b/compilerplugins/clang/test/unoaggregation.cxx
new file mode 100644
index 000000000000..01e0dd832e9d
--- /dev/null
+++ b/compilerplugins/clang/test/unoaggregation.cxx
@@ -0,0 +1,42 @@
+/* -*- 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/.
+ */
+
+#include <sal/config.h>
+
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XMain.hpp>
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <sal/types.h>
+
+class Base : public cppu::WeakAggImplHelper1<css::lang::XInitialization>
+{
+public:
+ void SAL_CALL initialize(css::uno::Sequence<css::uno::Any> const& aArguments) override;
+};
+
+class Good : public Base, public css::lang::XMain
+{
+public:
+ css::uno::Any SAL_CALL queryInterface(css::uno::Type const& aType) override
+ {
+ return Base::queryInterface(aType);
+ }
+};
+
+class Bad : public cppu::ImplInheritanceHelper<Base, css::lang::XMain>
+{
+public:
+ sal_Int32 SAL_CALL run(css::uno::Sequence<OUString> const& aArguments) override;
+};
+
+// expected-error@cppuhelper/implbase.hxx:* {{'ImplInheritanceHelper<Base, com::sun::star::lang::XMain>' derives from XAggregation, but its implementation of queryInterface does not delegate to an appropriate base class queryInterface [loplugin:unoaggregation]}}
+Bad bad; //make sure Bad's base cppu::ImplInheritanceHelper<Base, css::lang::XMain> is instantiated
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */