summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-04-26 22:07:21 +0200
committerStephan Bergmann <sbergman@redhat.com>2020-04-27 07:19:30 +0200
commitb512ce255f46d90e682634e4dd17e146af7f9080 (patch)
treeda2ce68b775e0e45294920074a1ae8306dbac818 /include
parent83cf08b1cb2d493a4c12f88eb6bf0daf25fe5beb (diff)
Make upcasting css::uno::Reference ctor require complete types
The main reason for the "home-grown" UpCast introduced with 904b3d1fceee5827076758ed2a81f80cb73493ca "Up-cast conversion constructor for css::uno::Reference" in 2013 was probably that we could not yet rely on C++11 std::is_base_of back then. A (welcome) side effect was that the derived class could be incomplete. However, specializations of UpCast relying on whether or not T2 is incomplete are obviously an ODR violation if the type is incomplete in some TUs and complete (and derived from T1) in others. And even if UpCast had internal linkage, it would still be brittle that its behavior depends on the completeness of T2 at the point of the template's instantiation, and not necessarily at the point of use. That means we should better base that ctor on std::is_base_of (which we can do now since 39a1edd6fec902ef378acce8af42c4d7fba280d0 "Make css::uno::Reference upcast ctor LIBO_INTERNAL_ONLY"), which causes a compilation error at least on Clang and GCC if the completeness requirements are not met. This change fixes all the cases where types need to be complete now, plus any resulting loplugin:referencecasting warnings ("the source reference is already a subtype of the destination reference"). Change-Id: Ieb9e3552e90adbf2c5a5af933dcb872e20661a2f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92950 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/com/sun/star/uno/Reference.h53
-rw-r--r--include/com/sun/star/uno/Reference.hxx4
-rw-r--r--include/vbahelper/vbahelperinterface.hxx5
3 files changed, 11 insertions, 51 deletions
diff --git a/include/com/sun/star/uno/Reference.h b/include/com/sun/star/uno/Reference.h
index 951902b356bd..0221f0ca5f54 100644
--- a/include/com/sun/star/uno/Reference.h
+++ b/include/com/sun/star/uno/Reference.h
@@ -24,6 +24,10 @@
#include <cassert>
#include <cstddef>
+#if defined LIBO_INTERNAL_ONLY
+#include <type_traits>
+#endif
+
#include "rtl/alloc.h"
namespace com
@@ -167,51 +171,6 @@ enum UnoReference_SetThrow
UNO_SET_THROW
};
-#if defined LIBO_INTERNAL_ONLY
-/// @cond INTERNAL
-namespace detail {
-
-// A mechanism to enable up-casts, used by the Reference conversion constructor,
-// but at the same time disable up-casts to XInterface, so that the conversion
-// operator for that special case is used in an expression like
-// Reference< XInterface >(x); heavily borrowed from boost::is_base_and_derived
-// (which manages to avoid compilation problems with ambiguous bases and cites
-// comp.lang.c++.moderated mail <http://groups.google.com/groups?
-// selm=df893da6.0301280859.522081f7%40posting.google.com> "SuperSubclass
-// (is_base_and_derived) complete implementation!" by Rani Sharoni and cites
-// Aleksey Gurtovoy for the workaround for MSVC), to avoid including Boost
-// headers in URE headers (basing on C++11 std::is_base_of does not work when the types are
-// incomplete):
-
-template< typename T1, typename T2 > struct UpCast {
-private:
- template< bool, typename U1, typename > struct C
- { typedef U1 t; };
-
- template< typename U1, typename U2 > struct C< false, U1, U2 >
- { typedef U2 t; };
-
- struct S { char c[2]; };
-
- template< typename U > static char f(T2 *, U);
- static S f(T1 *, int);
-
- struct H {
- H(); // avoid C2514 "class has no constructors" from MSVC
- operator T1 * () const;
- operator T2 * ();
- };
-
-public:
- typedef typename C< sizeof (f(H(), 0)) == 1, void *, void >::t t;
-};
-
-template< typename T2 > struct UpCast< XInterface, T2 > {};
-
-}
-/// @endcond
-#endif
-
/** Template reference class for interface type derived from BaseReference.
A special constructor given the UNO_QUERY identifier queries interfaces
for reference type.
@@ -314,7 +273,9 @@ public:
template< class derived_type >
inline Reference(
const Reference< derived_type > & rRef,
- typename detail::UpCast< interface_type, derived_type >::t = 0 );
+ std::enable_if_t<
+ std::is_base_of_v<interface_type, derived_type>
+ && !std::is_same_v<interface_type, XInterface>, void *> = nullptr);
#endif
/** Constructor: Sets given interface pointer.
diff --git a/include/com/sun/star/uno/Reference.hxx b/include/com/sun/star/uno/Reference.hxx
index b3c01aaa2391..c78f2681e3d5 100644
--- a/include/com/sun/star/uno/Reference.hxx
+++ b/include/com/sun/star/uno/Reference.hxx
@@ -135,7 +135,9 @@ inline Reference< interface_type >::Reference( Reference< interface_type > && rR
template< class interface_type > template< class derived_type >
inline Reference< interface_type >::Reference(
const Reference< derived_type > & rRef,
- typename detail::UpCast< interface_type, derived_type >::t )
+ std::enable_if_t<
+ std::is_base_of_v<interface_type, derived_type>
+ && !std::is_same_v<interface_type, XInterface>, void *>)
{
interface_type * p = rRef.get();
_pInterface = p;
diff --git a/include/vbahelper/vbahelperinterface.hxx b/include/vbahelper/vbahelperinterface.hxx
index 20f3d7ab77ce..5feb4ab83eba 100644
--- a/include/vbahelper/vbahelperinterface.hxx
+++ b/include/vbahelper/vbahelperinterface.hxx
@@ -24,6 +24,7 @@
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/RuntimeException.hpp>
#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/XComponentContext.hpp>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/weakref.hxx>
#include <ooo/vba/XHelperInterface.hpp>
@@ -31,10 +32,6 @@
#include <sal/types.h>
#include <vbahelper/vbahelper.hxx>
-namespace com { namespace sun { namespace star {
- namespace uno { class XComponentContext; } }
-} }
-
// use this class when you have an object like
// interface XAnInterface which contains XHelperInterface in its inheritance hierarchy
// interface XAnInterface