config_host/config_global.h.in |    1 +
 configure.ac                   |   15 +++++++++++++++
 include/vcl/vclptr.hxx         |   19 +++++++++++++++++++
 3 files changed, 35 insertions(+)

New commits:
commit dc01bb6306016346e52d654c3c46e4d21211964e
Author:     Stephan Bergmann <stephan.bergm...@collabora.com>
AuthorDate: Mon Jul 21 16:42:28 2025 +0200
Commit:     Stephan Bergmann <stephan.bergm...@collabora.com>
CommitDate: Mon Jul 21 18:11:10 2025 +0200

    Silence new GCC 16 trunk -Wsfinae-incomplete for now
    
    ...which was introduced in
    
<https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=117782e0c2a81a4b8170f87f0fe7190ee22548e2>
    "c++: add -Wsfinae-incomplete" and causes warnings like
    
    > In file included from include/vcl/event.hxx:28,
    >                  from libreofficekit/source/gtk/lokdocview.cxx:26:
    > include/vcl/outdev.hxx:160:37: error: defining ‘OutputDevice’, which 
previously failed to be complete in a SFINAE context 
[-Werror=sfinae-incomplete=]
    >   160 | class SAL_WARN_UNUSED VCL_DLLPUBLIC OutputDevice : public virtual 
VclReferenceBase
    >       |                                     ^~~~~~~~~~~~
    > In file included from include/vcl/vclevent.hxx:24,
    >                  from include/svtools/colorcfg.hxx:29,
    >                  from include/vcl/themecolors.hxx:12,
    >                  from include/vcl/settings.hxx:26,
    >                  from include/vcl/event.hxx:26:
    > include/vcl/vclptr.hxx:44:13: note: here.  Use ‘-Wsfinae-incomplete=2’ 
for a diagnostic at that point
    >    44 |     int (*)[sizeof(T)])
    >       |             ^~~~~~~~~
    
    because
    
    > include/vcl/vclptr.hxx:44:13: error: failed to complete ‘OutputDevice’ in 
SFINAE context [-Werror=sfinae-incomplete=]
    >    44 |     int (*)[sizeof(T)])
    >       |             ^~~~~~~~~
    > include/vcl/vclptr.hxx: In substitution of ‘template<class T> constexpr 
bool vcl::detail::isIncompleteOrDerivedFromVclReferenceBase(int (*)[sizeof 
(T)]) [with T = VirtualDevice]’:
    > include/vcl/vclptr.hxx:60:79:   required from ‘class 
VclPtr<VirtualDevice>’
    >    60 |         
vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
    >       |         
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    >    61 |             nullptr),
    >       |             ~~~~~~~~
    > include/vcl/outdev.hxx:188:37:   required from here
    >   188 |     VclPtr<VirtualDevice>           mpAlphaVDev;
    >       |                                     ^~~~~~~~~~~
    
    As discussed in the newly added comment in include/vcl/vclptr.hxx, until we 
can
    address this with C++26 reflection, "use a HACK of (globally) ignoring that
    warning".  (Which required adding a new HAVE_GCC_WSFINAE_INCOMPLETE 
configure
    check.)
    
    Change-Id: Ie1b44e730cf6b6269572158f6bd50e8911c15846
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188115
    Reviewed-by: Stephan Bergmann <stephan.bergm...@collabora.com>
    Tested-by: Jenkins

diff --git a/config_host/config_global.h.in b/config_host/config_global.h.in
index 5b42b2c5a8bd..6580fdfd0af7 100644
--- a/config_host/config_global.h.in
+++ b/config_host/config_global.h.in
@@ -13,6 +13,7 @@ Any change in this header will cause a rebuild of almost 
everything.
 #define CONFIG_GLOBAL_H
 
 #define HAVE_GCC_BUILTIN_ATOMIC 0
+#define HAVE_GCC_WSFINAE_INCOMPLETE 0
 #define HAVE_SYSLOG_H 0
 
 // Compiler supports C++20 
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1073r3.html>
diff --git a/configure.ac b/configure.ac
index f3761d0eeca6..f8433c6655a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -8013,6 +8013,21 @@ AC_SUBST(HARDENING_LDFLAGS)
 AC_SUBST(HARDENING_CFLAGS)
 AC_SUBST(HARDENING_OPT_CFLAGS)
 
+if test "$GCC" = yes && test "$COM_IS_CLANG" != TRUE; then
+    AC_MSG_CHECKING([whether $CXX_BASE supports -Wsfinae-incomplete])
+    AC_LANG_PUSH([C++])
+    save_CXXFLAGS=$CFLAGS
+    CXXFLAGS="$CXXFLAGS -Werror"
+    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+            #pragma GCC diagnostic warning "-Wsfinae-incomplete"
+        ])], [
+            AC_DEFINE([HAVE_GCC_WSFINAE_INCOMPLETE])
+            AC_MSG_RESULT([yes])
+        ], [AC_MSG_RESULT([no])])
+    CXXFLAGS=$save_CXXFLAGS
+    AC_LANG_POP([C++])
+fi
+
 dnl ===================================================================
 dnl Identify the C++ library
 dnl ===================================================================
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx
index 228a14c27482..8333f1a1b1a4 100644
--- a/include/vcl/vclptr.hxx
+++ b/include/vcl/vclptr.hxx
@@ -22,6 +22,7 @@
 
 #include <sal/config.h>
 
+#include <config_global.h>
 #include <rtl/ref.hxx>
 
 #include <utility>
@@ -44,6 +45,24 @@ template<typename T> constexpr bool 
isIncompleteOrDerivedFromVclReferenceBase(
     int (*)[sizeof(T)])
 { return std::is_base_of<VclReferenceBase, T>::value; }
 
+// The above isIncompleteOrDerivedFromVclReferenceBase will cause will cause 
-Wsfinae-incomplete
+// warnings when e.g. OutputDevice (include/vcl/outdev.hxx) contains members 
of type
+// VclPtr<OutputDevice>, so OutputDevice is not yet complete when
+// sIncompleteOrDerivedFromVclReferenceBase is instantiated, but will become 
complete later on
+// ("warning: error: defining ‘OutputDevice’, which previously failed to be 
complete in a SFINAE
+// context [-Werror=sfinae-incomplete=]").  A real solution would presumably 
be using C++26
+// reflection and rewriting the above 
isIncompleteOrDerivedFromVclReferenceBase as something like
+//
+//  consteval bool isIncompleteOrDerivedFromVclReferenceBase(std::meta::info 
type) {
+//      return !std::meta::is_complete_type(type)
+//          || std::meta::is_base_of_type(^^VclReferenceBase, type);
+//  }
+//
+// But until then, use a HACK of (globally) ignoring that warning:
+#if defined __GNUC__ && !defined __clang__ && HAVE_GCC_WSFINAE_INCOMPLETE
+#pragma GCC diagnostic ignored "-Wsfinae-incomplete"
+#endif
+
 } // namespace vcl::detail
 
 /**

Reply via email to