diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx index 03fcd033beca..2c8f938e6bb1 100644 --- a/codemaker/source/cppumaker/cpputype.cxx +++ b/codemaker/source/cppumaker/cpputype.cxx @@ -1184,7 +1184,7 @@ void InterfaceType::dumpHppFile( out << "\n"; addDefaultHxxIncludes(includes); includes.dump(out, &name_, !(m_cppuTypeLeak || m_cppuTypeDynamic)); - out << "\n"; + out << "\n#if defined LIBO_INTERNAL_ONLY\n#include \n#endif\n\n"; dumpGetCppuType(out); out << "\n::css::uno::Type const & " << codemaker::cpp::scopedCppName(u2b(name_)) @@ -1194,7 +1194,15 @@ void InterfaceType::dumpHppFile( dumpType(out, name_, false, false, true); out << " >::get();\n"; dec(); - out << "}\n\n#endif // "<< headerDefine << "\n"; + out << "}\n\n#if defined LIBO_INTERNAL_ONLY\nnamespace cppu::detail {\n"; + if (name_ == "com.sun.star.uno.XInterface") { + out << "template struct IsUnoInterfaceType: ::std::false_type {};\n" + "template inline constexpr auto isUnoInterfaceType =" + " IsUnoInterfaceType::value;\n"; + } + out << "template<> struct IsUnoInterfaceType<"; + dumpType(out, name_, false, false, true); + out << ">: ::std::true_type {};\n}\n#endif\n\n#endif // "<< headerDefine << "\n"; } void InterfaceType::dumpAttributes(FileStream & out) const diff --git a/include/unotools/weakref.hxx b/include/unotools/weakref.hxx index 554bd433b687..1d9b29f82e70 100644 --- a/include/unotools/weakref.hxx +++ b/include/unotools/weakref.hxx @@ -42,7 +42,9 @@ namespace unotools behind it *is* thread-safe, so multiple threads can have their own WeakReferences to the same XWeak object. - @tparam interface_type type of interface + @tparam interface_type Must be a C++ implementation class type, not a UNO interface type. (See + the C++20 requires-clause on the get member. That clause is not put on the class as a whole to + avoid overly tight requirements on when interface_type needs to be complete.) */ template class SAL_WARN_UNUSED WeakReference : public com::sun::star::uno::WeakReferenceHelper @@ -113,6 +115,9 @@ public: @return hard reference or null, if the weakly referenced interface has gone */ rtl::Reference SAL_CALL get() const +#if __cplusplus >= 202002L + requires(!cppu::detail::isUnoInterfaceType) +#endif { css::uno::Reference xInterface = WeakReferenceHelper::get(); // If XInterface is an ambiguous base of interface_type, we have to use dynamic_cast,