From c635f46439ba36088773bc6d5991c50e1d8e4e38 Mon Sep 17 00:00:00 2001 From: o9000 Date: Wed, 20 Dec 2017 18:55:50 +0100 Subject: [PATCH] Feature test C11 generics, since GCC lies about compliance --- CMakeLists.txt | 8 ++++++++ README.md | 1 - src/util/print.h | 6 ++++++ src/util/test.c | 6 ++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f28cc5..46dd7b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,14 @@ else() set(BACKTRACE_L_FLAGS "") endif() +check_c_source_compiles( + "#define print(x) _Generic((x), default : print_unknown)(x) \n void print_unknown(){} \n int main () { print(0); }" + HAS_GENERIC) + +if(HAS_GENERIC) + add_definitions(-DHAS_GENERIC) +endif(HAS_GENERIC) + if( ENABLE_RSVG ) pkg_check_modules( RSVG librsvg-2.0>=2.14.0 ) endif( ENABLE_RSVG ) diff --git a/README.md b/README.md index 2608b5d..eaca8ea 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,6 @@ tint2 is a simple panel/taskbar made for modern X window managers. It was specif * Graphical glitches on Intel graphics cards can be avoided by changing the acceleration method to UXA ([issue 595](https://gitlab.com/o9000/tint2/issues/595)) * Window managers that do not follow exactly the EWMH specification might not interact well with tint2 ([issue 627](https://gitlab.com/o9000/tint2/issues/627)). * Full transparency requires a compositor such as Compton (if not provided already by the window manager, as in Compiz/Unity, KDE or XFCE). - * As of version 16.0, tint2 requires a C11 compiler (such as GCC version 4.9 or newer). # How can I help out? diff --git a/src/util/print.h b/src/util/print.h index 52ac060..20ff81a 100644 --- a/src/util/print.h +++ b/src/util/print.h @@ -1,6 +1,8 @@ #ifndef PRINT_H #define PRINT_H +#ifdef HAS_GENERIC + int print_uchar(unsigned char v); int print_char(char v); @@ -52,4 +54,8 @@ int print_unknown(); void *: print_pointer, \ default : print_unknown)(x) +#else +#define print(...) printf("Omitted, the compiler does not support C11 generics.\n") +#endif + #endif diff --git a/src/util/test.c b/src/util/test.c index d375a0d..9cf3473 100644 --- a/src/util/test.c +++ b/src/util/test.c @@ -151,3 +151,9 @@ TEST(dummy) { int y = 2; ASSERT_EQUAL(x, y); } + +TEST(dummyBad) { + int x = 2; + int y = 3; + ASSERT_EQUAL(x, y); +}