X-Git-Url: http://git.samba.org/?p=metze%2Fwireshark%2Fwip.git;a=blobdiff_plain;f=ws_diag_control.h;h=52799f540b0522401d21869dc9931315f0d84ce9;hp=e3ee28ed9c16144400a194657619f7afa9efc382;hb=0ff7579101b8b3b7a1c4eecc6b4193d867da1ccc;hpb=72b57ac4ef653c1909e4c1d1daf40de2357b77e8 diff --git a/ws_diag_control.h b/ws_diag_control.h index e3ee28ed9c..52799f540b 100644 --- a/ws_diag_control.h +++ b/ws_diag_control.h @@ -48,6 +48,18 @@ extern "C" { #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) #define DIAG_ON(x) DIAG_PRAGMA(pop) #endif + + /* + * Not all versions of Clang understand -Wpedantic. Clang 4.0 appears + * to be the first version to do so. + */ + #if WS_IS_AT_LEAST_CLANG_VERSION(4,0) + #define DIAG_OFF_PEDANTIC DIAG_OFF(pedantic) + #define DIAG_ON_PEDANTIC DIAG_ON(pedantic) + #else + #define DIAG_OFF_PEDANTIC + #define DIAG_ON_PEDANTIC + #endif #elif defined(__GNUC__) /* * GCC, or a compiler (other than Clang) that claims to be GCC. @@ -65,6 +77,15 @@ extern "C" { #define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x) #define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) #define DIAG_ON(x) DIAG_PRAGMA(pop) + + /* + * We assume GCC 4.8 and later understand -Wpedantic. + */ + #define DIAG_OFF_PEDANTIC DIAG_OFF(pedantic) + #define DIAG_ON_PEDANTIC DIAG_ON(pedantic) + #else + #define DIAG_OFF_PEDANTIC + #define DIAG_ON_PEDANTIC #endif #endif @@ -79,6 +100,8 @@ extern "C" { */ #define DIAG_OFF(x) #define DIAG_ON(x) + #define DIAG_OFF_PEDANTIC + #define DIAG_ON_PEDANTIC #endif /* Use for clang specific pragmas, so we can keep -Wpragmas enabled */ @@ -91,8 +114,8 @@ extern "C" { #endif /* - * Suppress complaints about conversion of size_t to int and about - * signed vs. unsigned comparison. + * Suppress complaints about narrowing converstions and about signed vs. + * unsigned comparison. * * XXX - this is done solely to squelch complaints from code generated * by Flex, but newer versions of Flex might fix the code; can we @@ -104,19 +127,42 @@ extern "C" { * Suppress: * * warning C4018: signed/unsigned mismatch + * warning C4244: 'initializing' : conversion from '__int64' to 'int', possible loss of data * warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data + * + * as well as Visual Studio Code Analyzer warnings: + * + * warning C6011: Dereferencing NULL pointer + * warning C6308: 'realloc' might return null pointer + * warning C6386: Buffer overrun + * warning C6387: 'XXX' could be '0' + * warning C28182: Dereferencing NULL pointer */ #define DIAG_OFF_FLEX \ __pragma(warning(push)) \ __pragma(warning(disable:4018)) \ - __pragma(warning(disable:4267)) + __pragma(warning(disable:4244)) \ + __pragma(warning(disable:4267)) \ + __pragma(warning(disable:6011)) \ + __pragma(warning(disable:6308)) \ + __pragma(warning(disable:6386)) \ + __pragma(warning(disable:6387)) \ + __pragma(warning(disable:28182)) #define DIAG_ON_FLEX __pragma(warning(pop)) + + /* + * XXX - is there an issue with shadowed definitions with MSVC if + * somebody were to happen to use Berkeley YACC rather than Bison? + */ + #define DIAG_OFF_BYACC + #define DIAG_ON_BYACC #else /* * Suppress: * * -Wsigned-compare warnings * -Wshorten-64-to-32 warnings, if the compiler *has* -Wshorten-64-to-32 + * -Wunreachable-code warnings * * We use DIAG_OFF() and DIAG_ON(), so we only use features that the * compiler supports. @@ -133,8 +179,10 @@ extern "C" { #if defined(__clang__) || defined(__APPLE__) #define DIAG_OFF_FLEX \ DIAG_OFF(sign-compare) \ - DIAG_OFF(shorten-64-to-32) + DIAG_OFF(shorten-64-to-32) \ + DIAG_OFF(unreachable-code) #define DIAG_ON_FLEX \ + DIAG_ON(unreachable-code) \ DIAG_ON(shorten-64-to-32) \ DIAG_ON(sign-compare) #else @@ -143,6 +191,28 @@ extern "C" { #define DIAG_ON_FLEX \ DIAG_ON(sign-compare) #endif + + /* + * Berkeley YACC and, apparently, some versions of Bison, such as the + * one in Fedora 21, generate a global declaration of yylval, or the + * appropriately prefixed version of yylval, in grammar.h, *even + * though it's been told to generate a pure parser, meaning it + * doesn't have any global variables*. Other versions of Bison, such + * as the one in macOS Sierra don't do that. + * + * That causes a warning due to the local declaration in the parser + * shadowing the global declaration. + * + * So, if we have _Pragma, and have pragmas to suppress diagnostics, + * we use it to turn off -Wshadow warnings. + * + * XXX - do this for Bison only in versions of Bison with this + * problem? + */ + #define DIAG_OFF_BYACC \ + DIAG_OFF(shadow) + #define DIAG_ON_BYACC \ + DIAG_ON(shadow) #endif /*