include/com/sun/star/uno/Any.h | 10 ++++++++++ include/com/sun/star/uno/Any.hxx | 6 ++++++ 2 files changed, 16 insertions(+)
New commits: commit 7c1c72095af014d1635b76dff58cc91fb807abcc Author: Mike Kaganski <[email protected]> AuthorDate: Mon Sep 29 10:45:34 2025 +0200 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Sep 29 16:24:58 2025 +0200 Related: tdf#168599 Disallow constructing Any from const XInterface& See commit 16a0b42a4f79a20a2aaf8dd443c55b81a8084351, which fixed a code doing that accidentally, which wasn't caught by compiler, and caused a crash at runtime. This will prevent such code from compiling. Change-Id: Ibf6fdc118542fb4c7f941a928bec113bafab047e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191597 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/include/com/sun/star/uno/Any.h b/include/com/sun/star/uno/Any.h index d522d7309076..6efc711b6a3d 100644 --- a/include/com/sun/star/uno/Any.h +++ b/include/com/sun/star/uno/Any.h @@ -34,6 +34,10 @@ #include "com/sun/star/uno/TypeClass.hdl" #include "rtl/alloc.h" +#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) +#include <type_traits> +#endif + namespace com { namespace sun @@ -78,6 +82,12 @@ public: @param value value of the Any */ template <typename T> +#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) + // Disallow things like + // Reference<XInterface> x(...); + // Any a(*x); + requires (!std::is_base_of_v<XInterface, T>) +#endif explicit inline Any( T const & value ); /// Ctor support for C++ bool. explicit inline Any( bool value ); diff --git a/include/com/sun/star/uno/Any.hxx b/include/com/sun/star/uno/Any.hxx index 82f9447f50ac..d1e83dc54cf7 100644 --- a/include/com/sun/star/uno/Any.hxx +++ b/include/com/sun/star/uno/Any.hxx @@ -63,6 +63,12 @@ inline Any::Any() template <typename T> +#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) + // Disallow things like + // Reference<XInterface> x(...); + // Any a(*x); + requires(!std::is_base_of_v<XInterface, T>) +#endif inline Any::Any( T const & value ) { ::uno_type_any_construct(
