Unverified Commit 8cae9d7c authored by Niels Lohmann's avatar Niels Lohmann Committed by GitHub

Overwork warning flags (#2936)

* :alembic: update warning flags
parent f1e63a83
...@@ -88,21 +88,36 @@ file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp) ...@@ -88,21 +88,36 @@ file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp)
# Thorough check with recent compilers # Thorough check with recent compilers
############################################################################### ###############################################################################
# Ignored Clang warnings:
# -Wno-c++98-compat The library targets C++11.
# -Wno-c++98-compat-pedantic The library targets C++11.
# -Wno-deprecated-declarations The library contains annotations for deprecated functions.
# -Wno-extra-semi-stmt The library uses std::assert which triggers this warning.
# -Wno-padded We do not care about padding warnings.
# -Wno-covered-switch-default All switches list all cases and a default case.
# -Wno-weak-vtables The library is header-only.
set(CLANG_CXXFLAGS "-std=c++11 \ set(CLANG_CXXFLAGS "-std=c++11 \
-Werror \ -Werror \
-Weverything \ -Weverything \
-Wno-c++98-compat \ -Wno-c++98-compat \
-Wno-c++98-compat-pedantic \ -Wno-c++98-compat-pedantic \
-Wno-deprecated-declarations \ -Wno-deprecated-declarations \
-Wno-documentation-unknown-command \
-Wno-exit-time-destructors \
-Wno-extra-semi-stmt \ -Wno-extra-semi-stmt \
-Wno-padded \ -Wno-padded \
-Wno-range-loop-analysis \
-Wno-covered-switch-default \ -Wno-covered-switch-default \
-Wno-weak-vtables \ -Wno-weak-vtables \
") ")
# Ignored GCC warnings:
# -Wno-abi-tag We do not care about ABI tags.
# -Wno-aggregate-return The library uses aggregate returns.
# -Wno-long-long The library uses the long long type to interface with system functions.
# -Wno-namespaces The library uses namespaces.
# -Wno-padded We do not care about padding warnings.
# -Wno-system-headers We do not care about warnings in system headers.
# -Wno-templates The library uses templates.
set(GCC_CXXFLAGS "-std=c++11 \ set(GCC_CXXFLAGS "-std=c++11 \
-pedantic \ -pedantic \
-Werror \ -Werror \
...@@ -203,10 +218,16 @@ set(GCC_CXXFLAGS "-std=c++11 \ ...@@ -203,10 +218,16 @@ set(GCC_CXXFLAGS "-std=c++11 \
-Wextra-semi \ -Wextra-semi \
-Wfloat-conversion \ -Wfloat-conversion \
-Wfloat-equal \ -Wfloat-equal \
-Wformat-contains-nul \
-Wformat-diag \ -Wformat-diag \
-Wformat-extra-args \
-Wformat-nonliteral \
-Wformat-overflow=2 \ -Wformat-overflow=2 \
-Wformat-security \
-Wformat-signedness \ -Wformat-signedness \
-Wformat-truncation=2 \ -Wformat-truncation=2 \
-Wformat-y2k \
-Wformat-zero-length \
-Wformat=2 \ -Wformat=2 \
-Wframe-address \ -Wframe-address \
-Wfree-nonheap-object \ -Wfree-nonheap-object \
...@@ -249,7 +270,7 @@ set(GCC_CXXFLAGS "-std=c++11 \ ...@@ -249,7 +270,7 @@ set(GCC_CXXFLAGS "-std=c++11 \
-Wmultistatement-macros \ -Wmultistatement-macros \
-Wno-namespaces \ -Wno-namespaces \
-Wnarrowing \ -Wnarrowing \
-Wno-noexcept \ -Wnoexcept \
-Wnoexcept-type \ -Wnoexcept-type \
-Wnon-template-friend \ -Wnon-template-friend \
-Wnon-virtual-dtor \ -Wnon-virtual-dtor \
...@@ -277,7 +298,7 @@ set(GCC_CXXFLAGS "-std=c++11 \ ...@@ -277,7 +298,7 @@ set(GCC_CXXFLAGS "-std=c++11 \
-Wpragmas \ -Wpragmas \
-Wprio-ctor-dtor \ -Wprio-ctor-dtor \
-Wpsabi \ -Wpsabi \
-Wno-range-loop-construct \ -Wrange-loop-construct \
-Wredundant-decls \ -Wredundant-decls \
-Wredundant-move \ -Wredundant-move \
-Wredundant-tags \ -Wredundant-tags \
......
...@@ -64,4 +64,4 @@ type `#!cpp binary_t*` must be dereferenced. ...@@ -64,4 +64,4 @@ type `#!cpp binary_t*` must be dereferenced.
## Version history ## Version history
- Added in version 3.8.0. Changed type of subtype to `std::uint64_t` in version 3.9.2. - Added in version 3.8.0. Changed type of subtype to `std::uint64_t` in version 3.10.0.
...@@ -22,4 +22,4 @@ store ...@@ -22,4 +22,4 @@ store
## Version history ## Version history
- Added in version 3.9.0. Added value `store` in 3.9.2. - Added in version 3.9.0. Added value `store` in 3.10.0.
...@@ -18,7 +18,7 @@ order to override the binary type. ...@@ -18,7 +18,7 @@ order to override the binary type.
@tparam BinaryType container to store bytes (`std::vector<std::uint8_t>` by @tparam BinaryType container to store bytes (`std::vector<std::uint8_t>` by
default) default)
@since version 3.8.0; changed type of subtypes to std::uint64_t in 3.9.2. @since version 3.8.0; changed type of subtypes to std::uint64_t in 3.10.0.
*/ */
template<typename BinaryType> template<typename BinaryType>
class byte_container_with_subtype : public BinaryType class byte_container_with_subtype : public BinaryType
...@@ -108,7 +108,7 @@ class byte_container_with_subtype : public BinaryType ...@@ -108,7 +108,7 @@ class byte_container_with_subtype : public BinaryType
subtype subtype
@since version 3.8.0; fixed return value to properly return @since version 3.8.0; fixed return value to properly return
subtype_type(-1) as documented in version 3.9.2 subtype_type(-1) as documented in version 3.10.0
*/ */
constexpr subtype_type subtype() const noexcept constexpr subtype_type subtype() const noexcept
{ {
......
...@@ -38,8 +38,9 @@ ...@@ -38,8 +38,9 @@
// disable documentation warnings on clang // disable documentation warnings on clang
#if defined(__clang__) #if defined(__clang__)
#pragma GCC diagnostic push #pragma clang diagnostic push
#pragma GCC diagnostic ignored "-Wdocumentation" #pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
#endif #endif
// allow to disable exceptions // allow to disable exceptions
......
#pragma once #pragma once
// restore GCC/clang diagnostic settings // restore clang diagnostic settings
#if defined(__clang__) #if defined(__clang__)
#pragma GCC diagnostic pop #pragma clang diagnostic pop
#endif #endif
// clean up // clean up
......
...@@ -2250,8 +2250,9 @@ JSON_HEDLEY_DIAGNOSTIC_POP ...@@ -2250,8 +2250,9 @@ JSON_HEDLEY_DIAGNOSTIC_POP
// disable documentation warnings on clang // disable documentation warnings on clang
#if defined(__clang__) #if defined(__clang__)
#pragma GCC diagnostic push #pragma clang diagnostic push
#pragma GCC diagnostic ignored "-Wdocumentation" #pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
#endif #endif
// allow to disable exceptions // allow to disable exceptions
...@@ -5003,7 +5004,7 @@ order to override the binary type. ...@@ -5003,7 +5004,7 @@ order to override the binary type.
@tparam BinaryType container to store bytes (`std::vector<std::uint8_t>` by @tparam BinaryType container to store bytes (`std::vector<std::uint8_t>` by
default) default)
@since version 3.8.0; changed type of subtypes to std::uint64_t in 3.9.2. @since version 3.8.0; changed type of subtypes to std::uint64_t in 3.10.0.
*/ */
template<typename BinaryType> template<typename BinaryType>
class byte_container_with_subtype : public BinaryType class byte_container_with_subtype : public BinaryType
...@@ -5093,7 +5094,7 @@ class byte_container_with_subtype : public BinaryType ...@@ -5093,7 +5094,7 @@ class byte_container_with_subtype : public BinaryType
subtype subtype
@since version 3.8.0; fixed return value to properly return @since version 3.8.0; fixed return value to properly return
subtype_type(-1) as documented in version 3.9.2 subtype_type(-1) as documented in version 3.10.0
*/ */
constexpr subtype_type subtype() const noexcept constexpr subtype_type subtype() const noexcept
{ {
...@@ -26423,9 +26424,9 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std ...@@ -26423,9 +26424,9 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
// #include <nlohmann/detail/macro_unscope.hpp> // #include <nlohmann/detail/macro_unscope.hpp>
// restore GCC/clang diagnostic settings // restore clang diagnostic settings
#if defined(__clang__) #if defined(__clang__)
#pragma GCC diagnostic pop #pragma clang diagnostic pop
#endif #endif
// clean up // clean up
......
...@@ -27,13 +27,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ...@@ -27,13 +27,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// avoid warning when assert does not abort
#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wstrict-overflow"
#endif
#include "doctest_compatibility.h" #include "doctest_compatibility.h"
// avoid warning when assert does not abort
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow")
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wstrict-overflow")
/// global variable to record side effect of assert calls /// global variable to record side effect of assert calls
static int assert_counter; static int assert_counter;
...@@ -63,3 +64,6 @@ TEST_CASE("JSON_ASSERT(x)") ...@@ -63,3 +64,6 @@ TEST_CASE("JSON_ASSERT(x)")
} }
} }
#endif #endif
DOCTEST_GCC_SUPPRESS_WARNING_POP
DOCTEST_CLANG_SUPPRESS_WARNING_POP
...@@ -48,6 +48,10 @@ using nlohmann::json; ...@@ -48,6 +48,10 @@ using nlohmann::json;
#define JSON_HAS_CPP_14 #define JSON_HAS_CPP_14
#endif #endif
// NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
TEST_CASE("value conversion") TEST_CASE("value conversion")
{ {
SECTION("get an object (explicit)") SECTION("get an object (explicit)")
...@@ -1712,3 +1716,5 @@ TEST_CASE("JSON to enum mapping") ...@@ -1712,3 +1716,5 @@ TEST_CASE("JSON to enum mapping")
#ifdef JSON_HAS_CPP_14 #ifdef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_14 #undef JSON_HAS_CPP_14
#endif #endif
DOCTEST_CLANG_SUPPRESS_WARNING_POP
...@@ -29,6 +29,10 @@ SOFTWARE. ...@@ -29,6 +29,10 @@ SOFTWARE.
#include "doctest_compatibility.h" #include "doctest_compatibility.h"
// disable -Wnoexcept as exceptions are switched off for this test suite
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using json = nlohmann::json; using json = nlohmann::json;
...@@ -64,3 +68,5 @@ TEST_CASE("Tests with disabled exceptions") ...@@ -64,3 +68,5 @@ TEST_CASE("Tests with disabled exceptions")
delete sax_no_exception::error_string; // NOLINT(cppcoreguidelines-owning-memory) delete sax_no_exception::error_string; // NOLINT(cppcoreguidelines-owning-memory)
} }
} }
DOCTEST_GCC_SUPPRESS_WARNING_POP
...@@ -39,6 +39,12 @@ using nlohmann::json; ...@@ -39,6 +39,12 @@ using nlohmann::json;
#define JSON_HAS_CPP_14 #define JSON_HAS_CPP_14
#endif #endif
// This test suite uses range for loops where values are copied. This is inefficient in usual code, but required to achieve 100% coverage.
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct")
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wrange-loop-construct")
TEST_CASE("iterator_wrapper") TEST_CASE("iterator_wrapper")
{ {
SECTION("object") SECTION("object")
...@@ -1456,3 +1462,6 @@ TEST_CASE("items()") ...@@ -1456,3 +1462,6 @@ TEST_CASE("items()")
#ifdef JSON_HAS_CPP_14 #ifdef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_14 #undef JSON_HAS_CPP_14
#endif #endif
DOCTEST_GCC_SUPPRESS_WARNING_POP
DOCTEST_CLANG_SUPPRESS_WARNING_POP
...@@ -358,10 +358,10 @@ TEST_CASE("JSON pointers") ...@@ -358,10 +358,10 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str()); CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str());
} }
#if defined(_MSC_VER) // on some machines, the check below is not constant
#pragma warning (push) DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
#pragma warning (disable : 4127) // on some machines, the check below is not constant DOCTEST_MSVC_SUPPRESS_WARNING(4127)
#endif
if (sizeof(typename json::size_type) < sizeof(unsigned long long)) if (sizeof(typename json::size_type) < sizeof(unsigned long long))
{ {
auto size_type_max_uul = static_cast<unsigned long long>((std::numeric_limits<json::size_type>::max)()); auto size_type_max_uul = static_cast<unsigned long long>((std::numeric_limits<json::size_type>::max)());
...@@ -375,9 +375,7 @@ TEST_CASE("JSON pointers") ...@@ -375,9 +375,7 @@ TEST_CASE("JSON pointers")
CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str()); CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str());
} }
#if defined(_MSC_VER) DOCTEST_MSVC_SUPPRESS_WARNING_POP
#pragma warning (pop)
#endif
CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error&); CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error&);
CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1, CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1,
......
...@@ -29,6 +29,10 @@ SOFTWARE. ...@@ -29,6 +29,10 @@ SOFTWARE.
#include "doctest_compatibility.h" #include "doctest_compatibility.h"
// disable -Wnoexcept due to struct pod_bis
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using nlohmann::json; using nlohmann::json;
...@@ -95,3 +99,5 @@ TEST_CASE("runtime checks") ...@@ -95,3 +99,5 @@ TEST_CASE("runtime checks")
from_json(j2, pod_bis()); from_json(j2, pod_bis());
} }
} }
DOCTEST_GCC_SUPPRESS_WARNING_POP
...@@ -42,10 +42,9 @@ using nlohmann::json; ...@@ -42,10 +42,9 @@ using nlohmann::json;
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#if defined(_MSC_VER) // local variable is initialized but not referenced
#pragma warning (push) DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
#pragma warning (disable : 4189) // local variable is initialized but not referenced DOCTEST_MSVC_SUPPRESS_WARNING(4189)
#endif
TEST_CASE("README" * doctest::skip()) TEST_CASE("README" * doctest::skip())
{ {
...@@ -321,6 +320,4 @@ TEST_CASE("README" * doctest::skip()) ...@@ -321,6 +320,4 @@ TEST_CASE("README" * doctest::skip())
} }
} }
#if defined(_MSC_VER) DOCTEST_MSVC_SUPPRESS_WARNING_POP
#pragma warning (pop)
#endif
...@@ -53,6 +53,10 @@ using nlohmann::json; ...@@ -53,6 +53,10 @@ using nlohmann::json;
#include <span> #include <span>
#endif #endif
// NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// for #1021 // for #1021
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
...@@ -656,3 +660,5 @@ TEST_CASE("regression tests 2") ...@@ -656,3 +660,5 @@ TEST_CASE("regression tests 2")
static_assert(std::is_copy_assignable<nlohmann::ordered_json>::value, ""); static_assert(std::is_copy_assignable<nlohmann::ordered_json>::value, "");
} }
} }
DOCTEST_CLANG_SUPPRESS_WARNING_POP
...@@ -29,6 +29,10 @@ SOFTWARE. ...@@ -29,6 +29,10 @@ SOFTWARE.
#include "doctest_compatibility.h" #include "doctest_compatibility.h"
// disable -Wnoexcept due to class Evil
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using nlohmann::json; using nlohmann::json;
...@@ -845,3 +849,5 @@ TEST_CASE("Issue #1237") ...@@ -845,3 +849,5 @@ TEST_CASE("Issue #1237")
struct non_convertible_type {}; struct non_convertible_type {};
static_assert(!std::is_convertible<json, non_convertible_type>::value, ""); static_assert(!std::is_convertible<json, non_convertible_type>::value, "");
} }
DOCTEST_GCC_SUPPRESS_WARNING_POP
...@@ -41,6 +41,10 @@ using nlohmann::json; ...@@ -41,6 +41,10 @@ using nlohmann::json;
#include <iomanip> #include <iomanip>
#include <test_data.hpp> #include <test_data.hpp>
// this test suite uses static variables with non-trivial destructors
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
namespace namespace
{ {
extern size_t calls; extern size_t calls;
...@@ -623,3 +627,5 @@ TEST_CASE("Unicode (2/5)" * doctest::skip()) ...@@ -623,3 +627,5 @@ TEST_CASE("Unicode (2/5)" * doctest::skip())
} }
} }
} }
DOCTEST_CLANG_SUPPRESS_WARNING_POP
...@@ -41,6 +41,10 @@ using nlohmann::json; ...@@ -41,6 +41,10 @@ using nlohmann::json;
#include <iomanip> #include <iomanip>
#include <test_data.hpp> #include <test_data.hpp>
// this test suite uses static variables with non-trivial destructors
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
namespace namespace
{ {
extern size_t calls; extern size_t calls;
...@@ -337,3 +341,5 @@ TEST_CASE("Unicode (3/5)" * doctest::skip()) ...@@ -337,3 +341,5 @@ TEST_CASE("Unicode (3/5)" * doctest::skip())
} }
} }
} }
DOCTEST_CLANG_SUPPRESS_WARNING_POP
...@@ -41,6 +41,10 @@ using nlohmann::json; ...@@ -41,6 +41,10 @@ using nlohmann::json;
#include <iomanip> #include <iomanip>
#include <test_data.hpp> #include <test_data.hpp>
// this test suite uses static variables with non-trivial destructors
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
namespace namespace
{ {
extern size_t calls; extern size_t calls;
...@@ -337,3 +341,5 @@ TEST_CASE("Unicode (4/5)" * doctest::skip()) ...@@ -337,3 +341,5 @@ TEST_CASE("Unicode (4/5)" * doctest::skip())
} }
} }
} }
DOCTEST_CLANG_SUPPRESS_WARNING_POP
...@@ -41,6 +41,10 @@ using nlohmann::json; ...@@ -41,6 +41,10 @@ using nlohmann::json;
#include <iomanip> #include <iomanip>
#include <test_data.hpp> #include <test_data.hpp>
// this test suite uses static variables with non-trivial destructors
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
namespace namespace
{ {
extern size_t calls; extern size_t calls;
...@@ -337,3 +341,5 @@ TEST_CASE("Unicode (5/5)" * doctest::skip()) ...@@ -337,3 +341,5 @@ TEST_CASE("Unicode (5/5)" * doctest::skip())
} }
} }
} }
DOCTEST_CLANG_SUPPRESS_WARNING_POP
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