cjhash: use Q_FALLTHROUGH
authorOlivier Goffart <ogoffart@woboq.com>
Fri, 9 Nov 2018 15:43:35 +0000 (16:43 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:20 +0000 (10:58 +0100)
This fixes the warning
   warning: unknown option after â€˜#pragma GCC diagnostic’ kind [-Wpragmas]

Issue #6872

src/common/c_jhash.h

index 1b6c2fcdf5838c122ebc1cdd5d6dbb1bda2d2196..4790cf96a29f4148dc9225a1d3c388c209760f56 100644 (file)
 #define _C_JHASH_H
 
 #include <stdint.h> // NOLINT
+#include <QtCore/qglobal.h>
+#ifndef Q_FALLTHROUGH
+#define Q_FALLTHROUGH // Was added in Qt 5.8
+#endif
 
 #define c_hashsize(n) ((uint8_t) 1 << (n))
 #define c_hashmask(n) (xhashsize(n) - 1)
@@ -213,33 +217,29 @@ static inline uint64_t c_jhash64(const uint8_t *k, uint64_t length, uint64_t int
   /* handle the last 23 bytes */
   c += length;
   switch(len) {
-// pragma only for GCC (and clang continues to pretend to be it by defining __GNUC__)
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
-#endif
-    case 23: c+=((uint64_t)k[22]<<56);
-    case 22: c+=((uint64_t)k[21]<<48);
-    case 21: c+=((uint64_t)k[20]<<40);
-    case 20: c+=((uint64_t)k[19]<<32);
-    case 19: c+=((uint64_t)k[18]<<24);
-    case 18: c+=((uint64_t)k[17]<<16);
-    case 17: c+=((uint64_t)k[16]<<8);
+    case 23: c+=((uint64_t)k[22]<<56); Q_FALLTHROUGH();
+    case 22: c+=((uint64_t)k[21]<<48); Q_FALLTHROUGH();
+    case 21: c+=((uint64_t)k[20]<<40); Q_FALLTHROUGH();
+    case 20: c+=((uint64_t)k[19]<<32); Q_FALLTHROUGH();
+    case 19: c+=((uint64_t)k[18]<<24); Q_FALLTHROUGH();
+    case 18: c+=((uint64_t)k[17]<<16); Q_FALLTHROUGH();
+    case 17: c+=((uint64_t)k[16]<<8);  Q_FALLTHROUGH();
     /* the first byte of c is reserved for the length */
-    case 16: b+=((uint64_t)k[15]<<56);
-    case 15: b+=((uint64_t)k[14]<<48);
-    case 14: b+=((uint64_t)k[13]<<40);
-    case 13: b+=((uint64_t)k[12]<<32);
-    case 12: b+=((uint64_t)k[11]<<24);
-    case 11: b+=((uint64_t)k[10]<<16);
-    case 10: b+=((uint64_t)k[ 9]<<8);
-    case  9: b+=((uint64_t)k[ 8]);
-    case  8: a+=((uint64_t)k[ 7]<<56);
-    case  7: a+=((uint64_t)k[ 6]<<48);
-    case  6: a+=((uint64_t)k[ 5]<<40);
-    case  5: a+=((uint64_t)k[ 4]<<32);
-    case  4: a+=((uint64_t)k[ 3]<<24);
-    case  3: a+=((uint64_t)k[ 2]<<16);
-    case  2: a+=((uint64_t)k[ 1]<<8);
+    case 16: b+=((uint64_t)k[15]<<56); Q_FALLTHROUGH();
+    case 15: b+=((uint64_t)k[14]<<48); Q_FALLTHROUGH();
+    case 14: b+=((uint64_t)k[13]<<40); Q_FALLTHROUGH();
+    case 13: b+=((uint64_t)k[12]<<32); Q_FALLTHROUGH();
+    case 12: b+=((uint64_t)k[11]<<24); Q_FALLTHROUGH();
+    case 11: b+=((uint64_t)k[10]<<16); Q_FALLTHROUGH();
+    case 10: b+=((uint64_t)k[ 9]<<8);  Q_FALLTHROUGH();
+    case  9: b+=((uint64_t)k[ 8]);     Q_FALLTHROUGH();
+    case  8: a+=((uint64_t)k[ 7]<<56); Q_FALLTHROUGH();
+    case  7: a+=((uint64_t)k[ 6]<<48); Q_FALLTHROUGH();
+    case  6: a+=((uint64_t)k[ 5]<<40); Q_FALLTHROUGH();
+    case  5: a+=((uint64_t)k[ 4]<<32); Q_FALLTHROUGH();
+    case  4: a+=((uint64_t)k[ 3]<<24); Q_FALLTHROUGH();
+    case  3: a+=((uint64_t)k[ 2]<<16); Q_FALLTHROUGH();
+    case  2: a+=((uint64_t)k[ 1]<<8);  Q_FALLTHROUGH();
     case  1: a+=((uint64_t)k[ 0]);
     /* case 0: nothing left to add */
   }