From 36eb3a01fbed615d27b7942a0d76ed4232f59fa7 Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 20 Sep 2015 19:13:15 +0200 Subject: [PATCH] Disable clang unreachable-code warning for function ssl_id_callback Checking sizeof(pthread_t) > sizeof(unsigned long) has to be done at compile time, since the sizeof(...) operator can not be used in "#if" preprocessor conditions. Thus, depending on the compiler, either the if-branch or the else-branch will be logically dead code. There seems to be no reasonable way to prevent this, so disable -Wunreachable-code for this "if" statement. See #200 --- src/civetweb.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/civetweb.c b/src/civetweb.c index cf8ed356..651cdc4d 100755 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -9617,6 +9617,17 @@ static unsigned long ssl_id_callback(void) #ifdef _WIN32 return GetCurrentThreadId(); #else + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" +/* For every compiler, either "sizeof(pthread_t) > sizeof(unsigned long)" + * or not, so one of the two conditions will be unreachable by construction. + * Unfortunately the C standard does not define a way to check this at + * compile time, since the #if preprocessor conditions can not use the sizeof + * operator as an argument. */ +#endif + if (sizeof(pthread_t) > sizeof(unsigned long)) { /* This is the problematic case for CRYPTO_set_id_callback: * The OS pthread_t can not be cast to unsigned long. */ @@ -9633,6 +9644,11 @@ static unsigned long ssl_id_callback(void) } else { return (unsigned long)pthread_self(); } + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + #endif }