summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2022-01-18 16:34:02 +0100
committerHans Ulrich Niedermann <hun@n-dimensional.de>2022-01-22 16:38:42 +0100
commit6cbdd744b8d45fbc12fcbb3b35294613b672506d (patch)
tree51d729d12ff6fc3e9327fb02bb48147d3f9ca7e8
parent12676bbb86bd88f8062fddd6b8590ac99ae6a6c0 (diff)
downloadlibgphoto2-6cbdd744b8d45fbc12fcbb3b35294613b672506d.tar.gz
Allow clang compile with initializer overrides
This catches clang in a clang specific C preprocessor conditional before clang gets a chance to mess up at pretending to be gcc. The camlibs/pentax/js0n.c state machine tables use a lot of both GNU style range designators [ a ... b ], and later overrides some of the values in the range. This is not very pure C, but relatively effient to code, so we can accept silencing some warnings here. Fixes: https://github.com/gphoto/libgphoto2/issues/761
-rw-r--r--camlibs/pentax/js0n.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/camlibs/pentax/js0n.c b/camlibs/pentax/js0n.c
index 557ee7d70..890bb9269 100644
--- a/camlibs/pentax/js0n.c
+++ b/camlibs/pentax/js0n.c
@@ -4,6 +4,14 @@
#include <string.h> // one strncmp() is used to do key comparison, and a strlen(key) if no len passed in
#include "js0n.h"
+
+#ifdef __clang__
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Winitializer-overrides"
+
+#else /* to clang or not to clang */
+
// gcc started warning for the init syntax used here, is not helpful so don't generate the spam, suppressing the warning is really inconsistently supported across versions
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic push
@@ -13,6 +21,9 @@
#pragma GCC diagnostic ignored "-Winitializer-overrides"
#pragma GCC diagnostic ignored "-Woverride-init"
+#endif /* to clang or not to clang */
+
+
// only at depth 1, track start pointers to match key/value
#define PUSH(i) if(depth == 1) { if(!index) { val = cur+i; }else{ if(klen && index == 1) start = cur+i; else index--; } }
@@ -158,6 +169,15 @@ const char *js0n(const char *key, size_t klen,
}
+
+#ifdef __clang__
+
+#pragma clang diagnostic pop
+
+#else /* to clang or not to clang */
+
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic pop
#endif
+
+#endif /* to clang or not to clang */