From 81e584ed17902878579131776b4e5a9f7b54cdab Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 20 May 2017 14:01:03 +1000 Subject: CMake: Use GCC7's -Wimplicit-fallthrough=5 Use to avoid accidental missing break statements, use ATTR_FALLTHROUGH to suppress. --- intern/string/STR_HashedString.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'intern') diff --git a/intern/string/STR_HashedString.h b/intern/string/STR_HashedString.h index 8bfbde65895..ce790f398a0 100644 --- a/intern/string/STR_HashedString.h +++ b/intern/string/STR_HashedString.h @@ -38,6 +38,14 @@ #include "STR_String.h" +/* copied from 'BLI_compiler_attrs.h' */ +/* Use to suppress '-Wimplicit-fallthrough' (in place of 'break'). */ +#if defined(__GNUC__) && (__GNUC__ >= 7) /* gcc7.0+ only */ +#define ATTR_FALLTHROUGH __attribute__((fallthrough)) +#else +#define ATTR_FALLTHROUGH ((void)0) +#endif + // Hash Mix utility function, by Bob Jenkins - Mix 3 32-bit values reversibly // @@ -102,16 +110,16 @@ static dword STR_gHash(const void *in, int len, dword init_val) // Handle the last 11 bytes c += len; switch (length) { - case 11: c += ((dword)p_in[10] << 24); - case 10: c += ((dword)p_in[9] << 16); - case 9: c += ((dword)p_in[8] << 8); /* the first byte of c is reserved for the length */ - case 8: b += ((dword)p_in[7] << 24); - case 7: b += ((dword)p_in[6] << 16); - case 6: b += ((dword)p_in[5] << 8); - case 5: b += p_in[4]; - case 4: a += ((dword)p_in[3] << 24); - case 3: a += ((dword)p_in[2] << 16); - case 2: a += ((dword)p_in[1] << 8); + case 11: c += ((dword)p_in[10] << 24); ATTR_FALLTHROUGH; + case 10: c += ((dword)p_in[9] << 16); ATTR_FALLTHROUGH; + case 9: c += ((dword)p_in[8] << 8); ATTR_FALLTHROUGH; /* the first byte of c is reserved for the length */ + case 8: b += ((dword)p_in[7] << 24); ATTR_FALLTHROUGH; + case 7: b += ((dword)p_in[6] << 16); ATTR_FALLTHROUGH; + case 6: b += ((dword)p_in[5] << 8); ATTR_FALLTHROUGH; + case 5: b += p_in[4]; ATTR_FALLTHROUGH; + case 4: a += ((dword)p_in[3] << 24); ATTR_FALLTHROUGH; + case 3: a += ((dword)p_in[2] << 16); ATTR_FALLTHROUGH; + case 2: a += ((dword)p_in[1] << 8); ATTR_FALLTHROUGH; case 1: a += p_in[0]; } STR_gHashMix(a, b, c); -- cgit v1.2.3