Commit 813da24d authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

Add RAPIDJSON_DIAG_* macros to handle compiler warnings

Warning push/pop support has been added to GCC in version 4.6.0,
and pragmas to ignore certain warnings are present since 4.2.0.
This patch hides the compiler-specific warning push/pop/disable
pragmas behind a macro-based implementation (currently for MSVC and
clang /GCC.

This avoids warnings, as seen e.g. on GCC 4.4:
  ../../include/rapidjson/document.h:14: error: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
and earlier versions complaining about unknown pragmas being ignored.

Note: unittest.h and perftest.h need to check for compilers
explicitly, as rapidjson.h is not included there.
parent 9ff95ca2
......@@ -6,13 +6,11 @@
#include <new> // placement new
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
#elif defined(__GNUC__)
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
......@@ -1168,12 +1166,8 @@ GenericValue<Encoding,Allocator>::GenericValue(const GenericValue<Encoding,Sourc
} // namespace rapidjson
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#if defined(_MSC_VER) || defined(__GNUC__)
RAPIDJSON_DIAG_POP
#endif
#endif // RAPIDJSON_DOCUMENT_H_
......@@ -4,8 +4,8 @@
#include "rapidjson.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
namespace rapidjson {
......@@ -264,7 +264,7 @@ private:
} // namespace rapidjson
#ifdef __GNUC__
#pragma GCC diagnostic pop
RAPIDJSON_DIAG_POP
#endif
#endif // RAPIDJSON_FILESTREAM_H_
......@@ -4,8 +4,8 @@
#include "rapidjson.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
namespace rapidjson {
......@@ -530,7 +530,7 @@ struct Transcoder<Encoding, Encoding> {
} // namespace rapidjson
#ifdef __GNUC__
#pragma GCC diagnostic pop
RAPIDJSON_DIAG_POP
#endif
#endif // RAPIDJSON_ENCODINGS_H_
......@@ -4,8 +4,8 @@
#include "writer.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
namespace rapidjson {
......@@ -184,7 +184,7 @@ private:
} // namespace rapidjson
#ifdef __GNUC__
#pragma GCC diagnostic pop
RAPIDJSON_DIAG_POP
#endif
#endif // RAPIDJSON_RAPIDJSON_H_
......@@ -156,9 +156,56 @@ template<int x> struct StaticAssertTest {};
// Helpers
//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
#define RAPIDJSON_MULTILINEMACRO_BEGIN do {
#define RAPIDJSON_MULTILINEMACRO_END \
} while((void)0, 0)
// adopted from Boost
#define RAPIDJSON_VERSION_CODE(x,y,z) \
(((x)*100000) + ((y)*100) + (z))
// token stringification
#define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
#define RAPIDJSON_DO_STRINGIFY(x) #x
///////////////////////////////////////////////////////////////////////////////
// RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
#if defined(__clang__) || (defined(__GNUC__) && RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) >= RAPIDJSON_VERSION_CODE(4,2,0))
#define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
#define RAPIDJSON_DIAG_OFF(x) \
RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
// push/pop support in Clang and GCC>=4.6
#if defined(__clang__) || (defined(__GNUC__) && RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) >= RAPIDJSON_VERSION_CODE(4,6,0))
#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
#else // GCC >= 4.2, < 4.6
#define RAPIDJSON_DIAG_PUSH /* ignored */
#define RAPIDJSON_DIAG_POP /* ignored */
#endif
#elif defined(_MSC_VER)
// pragma (MSVC specific)
#define RAPIDJSON_PRAGMA(x) __pragma(x)
#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
#define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
#else
#define RAPIDJSON_DIAG_OFF(x) /* ignored */
#define RAPIDJSON_DIAG_PUSH /* ignored */
#define RAPIDJSON_DIAG_POP /* ignored */
#endif // RAPIDJSON_DIAG_*
//!@endcond
///////////////////////////////////////////////////////////////////////////////
......
......@@ -29,14 +29,16 @@
# define __STDC_CONSTANT_MACROS 1 // required by C++ standard
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
#pragma GCC diagnostic ignored "-Weffc++"
#if defined(__clang__) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic push
#endif
#endif
#include "gtest/gtest.h"
#ifdef __GNUC__
#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic pop
#endif
......
......@@ -172,8 +172,8 @@ TEST_F(RapidJson, DocumentTraverse) {
}
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
struct ValueCounter : public BaseReaderHandler<> {
......@@ -186,7 +186,7 @@ struct ValueCounter : public BaseReaderHandler<> {
};
#ifdef __GNUC__
#pragma GCC diagnostic pop
RAPIDJSON_DIAG_POP
#endif
TEST_F(RapidJson, DocumentAccept) {
......
......@@ -6,8 +6,8 @@
using namespace rapidjson;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
template<bool expect>
......@@ -707,5 +707,5 @@ TEST(Reader, Parse_IStreamWrapper_StringStream) {
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
RAPIDJSON_DIAG_POP
#endif
......@@ -13,14 +13,16 @@
#pragma warning(disable : 4996) // 'function': was declared deprecated
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
#pragma GCC diagnostic ignored "-Weffc++"
#if defined(__clang__) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic push
#endif
#endif
#include "gtest/gtest.h"
#ifdef __GNUC__
#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic pop
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment