Glib uses _Static_assert in C++17 mode
GCC >= 7 defines STDC_VERSION to 201112L in std=c++17 mode. This makes the following logic from gmacros.h wrong:
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
(defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
(defined (_MSC_VER) && (_MSC_VER >= 1800))
#define G_STATIC_ASSERT(expr) static_assert (expr, "Expression evaluates to false")
#else
#ifdef __COUNTER__
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
#else
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED
#endif
#endif /* __STDC_VERSION__ */
as _Static_assertion is not defined in C++ mode. Likely first line should have && !defined(__cplusplus)
Simple reproducer:
#include <glib-2.0/glib.h>
int main()
{
return 0;
}
/usr/gcc/7/bin/g++ -std=c++17 $(pkg-config --cflags gtk+-2.0) -c test.cc
In file included from /usr/lib/glib-2.0/include/glibconfig.h:9:0,
from /usr/include/glib-2.0/glib/gtypes.h:32,
from /usr/include/glib-2.0/glib/galloca.h:32,
from /usr/include/glib-2.0/glib.h:30,
from test.cc:1:
/usr/include/glib-2.0/glib/gtypes.h: In function 'gboolean _GLIB_CHECKED_ADD_U64(guint64*, guint64, guint64)':
/usr/include/glib-2.0/glib/gtypes.h:466:3: error: '_Static_assert' was not declared in this scope
G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
^
/usr/include/glib-2.0/glib/gtypes.h:466:3: note: suggested alternative: '__cpp_static_assert'