Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent json.hpp from emitting compiler warnings #154

Closed
luxe opened this issue Dec 9, 2015 · 9 comments
Closed

prevent json.hpp from emitting compiler warnings #154

luxe opened this issue Dec 9, 2015 · 9 comments

Comments

@luxe
Copy link
Contributor

luxe commented Dec 9, 2015

compiling json.hpp with g++.
I've enabled some warnings flags, and now get the following:

In file included from ./Test_Utilities/all_test_utilities.hpp:9:0,
                 from test.cpp:2:
./Test_Utilities/3rd_Party_Libs/json.hpp: In instantiation of ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::~basic_json() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’:
./Test_Utilities/3rd_Party_Libs/json.hpp:7286:56:   required from here
./Test_Utilities/3rd_Party_Libs/json.hpp:1669:9: warning: enumeration value ‘null’ not handled in switch [-Wswitch-enum]
         switch (m_type)
         ^
./Test_Utilities/3rd_Party_Libs/json.hpp:1669:9: warning: enumeration value ‘boolean’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp:1669:9: warning: enumeration value ‘number_integer’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp:1669:9: warning: enumeration value ‘number_float’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp:1669:9: warning: enumeration value ‘discarded’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp: In instantiation of ‘void nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::dump(std::ostream&, bool, unsigned int, unsigned int) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; std::ostream = std::basic_ostream<char>]’:
./Test_Utilities/3rd_Party_Libs/json.hpp:1739:17:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::dump(int) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>]’
./Test_Utilities/3rd_Party_Libs/json.hpp:7268:25:   required from here
./Test_Utilities/3rd_Party_Libs/json.hpp:4722:9: warning: enumeration value ‘null’ not handled in switch [-Wswitch-enum]
         switch (m_type)
         ^
./Test_Utilities/3rd_Party_Libs/json.hpp: In instantiation of ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse_internal(bool) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’:
./Test_Utilities/3rd_Party_Libs/json.hpp:6955:47:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:4429:36:   required from ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parse(const string_t&, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t = std::function<bool(int, nlohmann::basic_json<>::parse_event_t, nlohmann::basic_json<>&)>]’
./Test_Utilities/3rd_Party_Libs/json.hpp:7286:56:   required from here
./Test_Utilities/3rd_Party_Libs/json.hpp:6970:13: warning: enumeration value ‘uninitialized’ not handled in switch [-Wswitch-enum]
             switch (last_token)
             ^
./Test_Utilities/3rd_Party_Libs/json.hpp:6970:13: warning: enumeration value ‘end_array’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp:6970:13: warning: enumeration value ‘end_object’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp:6970:13: warning: enumeration value ‘name_separator’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp:6970:13: warning: enumeration value ‘value_separator’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp:6970:13: warning: enumeration value ‘parse_error’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp:6970:13: warning: enumeration value ‘end_of_input’ not handled in switch [-Wswitch-enum]
./Test_Utilities/3rd_Party_Libs/json.hpp: In instantiation of ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::basic_json(const nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>&) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’:
./Test_Utilities/3rd_Party_Libs/json.hpp:6961:42:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:4429:36:   required from ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parse(const string_t&, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t = std::function<bool(int, nlohmann::basic_json<>::parse_event_t, nlohmann::basic_json<>&)>]’
./Test_Utilities/3rd_Party_Libs/json.hpp:7286:56:   required from here
./Test_Utilities/3rd_Party_Libs/json.hpp:1553:9: warning: switch missing default case [-Wswitch-default]
         switch (m_type)
         ^
In file included from ./Test_Utilities/all_test_utilities.hpp:9:0,
                 from test.cpp:2:
./Test_Utilities/3rd_Party_Libs/json.hpp: In instantiation of ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::json_value::json_value(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_t) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’:
./Test_Utilities/3rd_Party_Libs/json.hpp:6978:40:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse_internal(bool) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:6955:47:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:4429:36:   required from ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parse(const string_t&, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t = std::function<bool(int, nlohmann::basic_json<>::parse_event_t, nlohmann::basic_json<>&)>]’
./Test_Utilities/3rd_Party_Libs/json.hpp:7286:56:   required from here
./Test_Utilities/3rd_Party_Libs/json.hpp:632:13: warning: switch missing default case [-Wswitch-default]
             switch (t)
             ^
In file included from ./Test_Utilities/all_test_utilities.hpp:9:0,
                 from test.cpp:2:
./Test_Utilities/3rd_Party_Libs/json.hpp: In instantiation of ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::lexer::get_string() const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>]’:
./Test_Utilities/3rd_Party_Libs/json.hpp:7009:61:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse_internal(bool) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:6955:47:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:4429:36:   required from ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parse(const string_t&, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t = std::function<bool(int, nlohmann::basic_json<>::parse_event_t, nlohmann::basic_json<>&)>]’
./Test_Utilities/3rd_Party_Libs/json.hpp:7286:56:   required from here
./Test_Utilities/3rd_Party_Libs/json.hpp:6795:21: warning: switch missing default case [-Wswitch-default]
                     switch (*i)
                     ^
./Test_Utilities/3rd_Party_Libs/json.hpp: In instantiation of ‘static std::string nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::lexer::token_type_name(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::lexer::token_type) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; std::string = std::basic_string<char>]’:
./Test_Utilities/3rd_Party_Libs/json.hpp:7194:61:   required from ‘void nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::expect(typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::lexer::token_type) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::lexer::token_type = nlohmann::basic_json<>::lexer::token_type]’
./Test_Utilities/3rd_Party_Libs/json.hpp:6957:19:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:4429:36:   required from ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parse(const string_t&, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t = std::function<bool(int, nlohmann::basic_json<>::parse_event_t, nlohmann::basic_json<>&)>]’
./Test_Utilities/3rd_Party_Libs/json.hpp:7286:56:   required from here
./Test_Utilities/3rd_Party_Libs/json.hpp:5922:13: warning: enumeration value ‘parse_error’ not handled in switch [-Wswitch-enum]
             switch (t)
             ^
./Test_Utilities/3rd_Party_Libs/json.hpp: In instantiation of ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::type_name() const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>]’:
./Test_Utilities/3rd_Party_Libs/json.hpp:2664:78:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_type& nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::operator[](const typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::object_t::key_type&) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::reference = nlohmann::basic_json<>&; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_type = nlohmann::basic_json<>; typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::object_t::key_type = std::basic_string<char>]’
./Test_Utilities/3rd_Party_Libs/json.hpp:7034:35:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse_internal(bool) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:6955:47:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser::parse() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’
./Test_Utilities/3rd_Party_Libs/json.hpp:4429:36:   required from ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parse(const string_t&, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t = std::basic_string<char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::parser_callback_t = std::function<bool(int, nlohmann::basic_json<>::parse_event_t, nlohmann::basic_json<>&)>]’
./Test_Utilities/3rd_Party_Libs/json.hpp:7286:56:   required from here
./Test_Utilities/3rd_Party_Libs/json.hpp:4508:9: warning: enumeration value ‘number_integer’ not handled in switch [-Wswitch-enum]
         switch (m_type)
         ^
./Test_Utilities/3rd_Party_Libs/json.hpp:4508:9: warning: enumeration value ‘number_float’ not handled in switch [-Wswitch-enum]

It's just -Wswitch-enum and -Wswitch-default.
Can we suppress these warnings in the library, so I can still apply them to my own code without all the noise?
The Catch testing framework, seems to take a similar approach.
https://github.com/philsquared/Catch/blob/master/include/internal/catch_suppress_warnings.h

@nlohmann
Copy link
Owner

nlohmann commented Dec 9, 2015

This is strange, because all switch statements are either complete or have a default branch. Could it be that your compiler switches require both?

@luxe
Copy link
Contributor Author

luxe commented Dec 9, 2015

Yes, with certain flags enabled, it seems that g++ requires a switch to contain both.. Not sure about clang.

Example:

// compiled with g++ -std=c++14 -Wswitch-default -Wswitch-enum -o test test.cpp
// g++ (Ubuntu 5.1.0-0ubuntu11~14.04.1) 5.1.0
enum class Test {ONE,TWO,THREE};

int main(){

  Test t = Test::ONE;

  // accounts for some enums
  // has no default case
  // *warns about missing default case.
  // *warns about missing Test::TWO case
  switch (t){
    case Test::ONE:   /* do something */ break;
    case Test::THREE: /* do something */ break;
  }

  // accounts for some enums
  // has a default case
  // *warns about missing Test::TWO case
  switch (t){
    case Test::ONE:   /* do something */ break;
    case Test::THREE: /* do something */ break;
    default:          /* do something */ break;
  }

  // accounts for all enums
  // has no default case
  // *warns about missing default case.
  switch (t){
    case Test::ONE:   /* do something */ break;
    case Test::TWO:   /* do something */ break;
    case Test::THREE: /* do something */ break;
  }

  // accounts for all enums
  // has a default case
  // *no warnings
  switch (t){
    case Test::ONE:    /* do something */ break;
    case Test::TWO:    /* do something */ break;
    case Test::THREE:  /* do something */ break;
    default:           /* do something */ break;
  }
}

Anyway, I agree that these warnings are acting like false positives for the json library. I don't want to turn them off though, because I like having as much noise as possible in my unit test builds. I'm not testing json.hpp itself though, so I'd like to avoid seeing those warnings.

I'm going to try and wrap #pragma diagnose ignore statements around the #include of the json library itself. It's not something that would really need to be added into your library code, but its worth mentioning as that seems to be what Catch does. With all my warning flags cranked up, I haven't seen any warnings emitted while including Catch, and I assume that's from the internal suppression pragmas that Catch utilizes.

@nlohmann
Copy link
Owner

nlohmann commented Dec 9, 2015

Please check. I would not want to alter correct code just to suppress overly pedantic compiler flags...

@luxe
Copy link
Contributor Author

luxe commented Dec 10, 2015

#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wswitch-enum"
#pragma GCC diagnostic ignored "-Wswitch-default"
#endif

#include "json.hpp"

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

Doing this solves my problem and suppresses warnings related to json.hpp.
Whether you want to pass this responsibility on to the users of the library(as I have demonstrated above), or handle it internally, that is up to you. None of the actual switch statement code would need changed, but it would require wrapping all of the json library code in the two macros chunks shown above.

calling @philsquared
You've done this.
Had you gotten similar complaints during Catch development that lead you to do it? Is it a good practice?

_

@nlohmann I'm satisfied to close the issue if you see fit.

@philsquared
Copy link

I've always striven to keep warnings generated from Catch as close to zero as possible - so have always compiled at highest warning levels.
Sometimes they can be really bizarre - and, when you include multiple compilers into the mix (and I can never test against enough of them) they can be contradictory!
In my experience with your example (enum cases) I initially added all cases, even where that didn't really make sense. But then found that some compilers would warn if you exhausted all cases and had a default. Others would complain if you didn't have a default.
In the end I gave up and added the warning suppression.
I don't like doing that in general - not least because you get into compiler specific territory - and sometimes suppressing a warning for one compiler causes warnings in others (usually the ones I don't have access to, of course!). But I've ended up (as you can see from the linked file) with quite a few.

It's a minefield - and one of the biggest pain points of writing portable (esp. header-only) code.
But the specific warnings being suppressed here should be fairly safe. That is: I've not (that I recall) had any complains about the use of the (properly guarded) pragmas (you might need to add an alternate set of clang - I can never remember which of GCCs it picks up).

@philsquared
Copy link

BTW: great to see such a comprehensive test suite using Catch - and with good use of nested sections, no less :-)

@nlohmann
Copy link
Owner

@luxe - I cleaned up the code. Using Clang and GCC, I do not get any switch-related warnings.

@philsquared - Thanks for Catch! :)

@nlohmann nlohmann reopened this Dec 14, 2015
@nlohmann
Copy link
Owner

I just saw that there would be again warnings with -Wcovered-switch-default. My previous commit was too optimistic. I shall focus on having a default branch in all switches and do not care about pedantic compiler flags...

nlohmann added a commit that referenced this issue Dec 14, 2015
@luxe
Copy link
Contributor Author

luxe commented Dec 14, 2015

@nlohmann thanks, appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants