#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.
#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
*/
#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 */
#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
* 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.
#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
#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
/*