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.bergmann@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Stephan Bergmann
2025-07-21 16:42:28 +02:00
parent 4d6429c036
commit dc01bb6306
3 changed files with 35 additions and 0 deletions

View File

@ -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>

View File

@ -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 ===================================================================

View File

@ -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
/**