diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-12-13 16:52:41 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-12-14 09:34:01 +0000 |
commit | c826ddfc2c213ae61918793eefe0c6593ce9bb17 (patch) | |
tree | 8bdc80a87fefdc35e2a6a45ad340a7a3e35f0386 /include | |
parent | 876de03290ce0e9393134d722e5b15025e32a341 (diff) |
Check that VclPtr is only instantiated with appropriate types
...deriving from VclReferenceBase. Complicated by the fact that the argument
type may be incomplete at the time of template instantiation. So this approach
may be less precise than the change to loplugin:vclwidgets from
cbf5b21f2a65bbb342295200f6ad93a00f90733e "Catch some misuses of VclPtr
construction" when the argument type becomes complete later in the comilation
unit. However, this approach would also catch the two misuses in UnoControls
found by cbf5b21f2a65bbb342295200f6ad93a00f90733e, so go with this approach for
now and revert the change to loplugin:vclwdigets.
Change-Id: I7888f23d2b9e2db81ae2ce4bf4c8277912317685
Reviewed-on: https://gerrit.libreoffice.org/31966
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/vcl/vclptr.hxx | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx index c022d8b5352c..22679e69ed3d 100644 --- a/include/vcl/vclptr.hxx +++ b/include/vcl/vclptr.hxx @@ -20,7 +20,12 @@ #ifndef INCLUDED_VCL_PTR_HXX #define INCLUDED_VCL_PTR_HXX +#include <sal/config.h> + +#include <config_global.h> #include <rtl/ref.hxx> +#include <vcl/vclreferencebase.hxx> + #include <utility> #include <type_traits> @@ -60,6 +65,17 @@ public: typedef typename C< value, void *, void >::t t; }; +#if HAVE_CXX11_CONSTEXPR + +template<typename> +constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } + +template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( + int (*)[sizeof(T)]) +{ return std::is_base_of<VclReferenceBase, T>::value; } + +#endif + }; }; // namespace detail, namespace vcl /// @endcond @@ -71,9 +87,18 @@ public: * * @param reference_type must be a subclass of vcl::Window */ +namespace detail { +} template <class reference_type> class VclPtr { +#if HAVE_CXX11_CONSTEXPR + static_assert( + vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( + nullptr), + "template argument type must be derived from VclReferenceBase"); +#endif + ::rtl::Reference<reference_type> m_rInnerRef; public: |