msys2-clang64 fails to compile cxx tests on versions < 11
As visible in https://gitlab.gnome.org/sdroege/gobject-introspection/-/jobs/2361666
FAILED: subprojects/glib/glib/tests/cxx-98.exe.p/cxx.cpp.obj
"ccache" "c++" "-Isubprojects/glib/glib/tests/cxx-98.exe.p" "-Isubprojects/glib/glib/tests" "-I../subprojects/glib/glib/tests" "-Isubprojects/glib" "-I../subprojects/glib" "-Isubprojects/glib/glib" "-I../subprojects/glib/glib" "-fcolor-diagnostics" "-D_FILE_OFFSET_BITS=64" "-Wall" "-Winvalid-pch" "-Wnon-virtual-dtor" "-Wextra" "-Wpedantic" "-O0" "-g" "-Wimplicit-fallthrough" "-Wmisleading-indentation" "-Wunused" "-Wno-unused-parameter" "-Wno-cast-function-type" "-Wno-pedantic" "-Wno-format-zero-length" "-Wno-variadic-macros" "-Werror=format=2" "-Werror=init-self" "-Werror=missing-include-dirs" "-Werror=pointer-arith" "-Werror=unused-result" "-DG_LOG_DOMAIN=\"GLib\"" "-UG_DISABLE_ASSERT" "-std=c++98" -MD -MQ subprojects/glib/glib/tests/cxx-98.exe.p/cxx.cpp.obj -MF "subprojects/glib/glib/tests/cxx-98.exe.p/cxx.cpp.obj.d" -o subprojects/glib/glib/tests/cxx-98.exe.p/cxx.cpp.obj "-c" ../subprojects/glib/glib/tests/cxx.cpp
../subprojects/glib/glib/tests/cxx.cpp:50:3: error: '_GStaticAssertCompileTimeAssertion_2' declared as an array with a negative size
g_atomic_pointer_compare_and_exchange (&obj5, NULL, obj4);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../subprojects/glib/glib/gatomic.h:244:5: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../subprojects/glib/glib/gmacros.h:831:103: note: expanded from macro 'G_STATIC_ASSERT'
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
^~~~~~~~~~~~~~~
../subprojects/glib/glib/tests/cxx.cpp:201:34: warning: missing sentinel in function call [-Wsentinel]
g_test_init (&argc, &argv, NULL);
[341/1354] Compiling C++ object subprojects/glib/glib/tests/cxx.exe.p/cxx.cpp.obj
[342/1354] Linking target subprojects/glib/glib/tests/642026-ec.exe
[343/1354] Linking target subprojects/glib/glib/tests/642026.exe
[344/1354] Compiling C++ object subprojects/glib/glib/tests/cxx-03.exe.p/cxx.cpp.obj
FAILED: subprojects/glib/glib/tests/cxx-03.exe.p/cxx.cpp.obj
"ccache" "c++" "-Isubprojects/glib/glib/tests/cxx-03.exe.p" "-Isubprojects/glib/glib/tests" "-I../subprojects/glib/glib/tests" "-Isubprojects/glib" "-I../subprojects/glib" "-Isubprojects/glib/glib" "-I../subprojects/glib/glib" "-fcolor-diagnostics" "-D_FILE_OFFSET_BITS=64" "-Wall" "-Winvalid-pch" "-Wnon-virtual-dtor" "-Wextra" "-Wpedantic" "-O0" "-g" "-Wimplicit-fallthrough" "-Wmisleading-indentation" "-Wunused" "-Wno-unused-parameter" "-Wno-cast-function-type" "-Wno-pedantic" "-Wno-format-zero-length" "-Wno-variadic-macros" "-Werror=format=2" "-Werror=init-self" "-Werror=missing-include-dirs" "-Werror=pointer-arith" "-Werror=unused-result" "-DG_LOG_DOMAIN=\"GLib\"" "-UG_DISABLE_ASSERT" "-std=c++03" -MD -MQ subprojects/glib/glib/tests/cxx-03.exe.p/cxx.cpp.obj -MF "subprojects/glib/glib/tests/cxx-03.exe.p/cxx.cpp.obj.d" -o subprojects/glib/glib/tests/cxx-03.exe.p/cxx.cpp.obj "-c" ../subprojects/glib/glib/tests/cxx.cpp
../subprojects/glib/glib/tests/cxx.cpp:50:3: error: '_GStaticAssertCompileTimeAssertion_2' declared as an array with a negative size
g_atomic_pointer_compare_and_exchange (&obj5, NULL, obj4);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../subprojects/glib/glib/gatomic.h:244:5: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../subprojects/glib/glib/gmacros.h:831:103: note: expanded from macro 'G_STATIC_ASSERT'
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
^~~~~~~~~~~~~~~
Now, the problem here seems to be mostly on this Clang setup, as it doesn't appear to happen on unix. And it's probably due to various problems:
- Compiler in -std 03 and 98 modes is not really using it fully as we're still using the
__ATOMIC_SEQ_CST
route, while it should not be the case- At the same time, we wanted this to happen for compilers exposing such API to fix another issue (see a0f20059)
- In any case the compiler should not fail in considering NULL the same size of gpointer if such standard is defined.
- I think our definition of
NULL
could be wrong in this case, as0L
is probably not as(intptr_t) 0
. - I'd be curious to check if
__intptr_t_defined
is set in this mixture, but probably it is.
Edited by Marco Trevisan