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

warnings in MSVC (2015) in 3.4.0 related to bool... #1364

Closed
ziggurat29 opened this issue Nov 19, 2018 · 3 comments
Closed

warnings in MSVC (2015) in 3.4.0 related to bool... #1364

ziggurat29 opened this issue Nov 19, 2018 · 3 comments
Assignees
Labels
platform: visual studio related to MSVC release item: ⚡ improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@ziggurat29
Copy link

I just updated to 3.4.0 from 3.3.0 and some new warnings have appeared that were not present before.
They relate to 'bool'; MSVC warns if there is a integral type demoted to 'bool' type.
These were emitted in 3.3.0.

c:\experiments\sixengines\gits\forethoughtengine001\forethoughtengine001\forethoughtenginelib001\product\../srclibs/json/json.hpp(6585): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
  c:\experiments\sixengines\gits\forethoughtengine001\forethoughtengine001\forethoughtenginelib001\product\../srclibs/json/json.hpp(6557): note: while compiling class template member function 'bool nlohmann::detail::binary_reader<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>,SAX>::parse_bson_element_internal(const int,const std::size_t)'
          with
          [
              SAX=`anonymous-namespace'::sax_lua_tbl_builder
          ]
  c:\experiments\sixengines\gits\forethoughtengine001\forethoughtengine001\forethoughtenginelib001\product\../srclibs/json/json.hpp(6650): note: see reference to function template instantiation 'bool nlohmann::detail::binary_reader<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>,SAX>::parse_bson_element_internal(const int,const std::size_t)' being compiled
          with
          [
              SAX=`anonymous-namespace'::sax_lua_tbl_builder
          ]
  c:\experiments\sixengines\gits\forethoughtengine001\forethoughtengine001\forethoughtenginelib001\product\../srclibs/json/json.hpp(18390): note: see reference to class template instantiation 'nlohmann::detail::binary_reader<nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>,SAX>' being compiled
          with
          [
              SAX=`anonymous-namespace'::sax_lua_tbl_builder
          ]
  product\lua_runtime_setup.cpp(464): note: see reference to function template instantiation 'bool nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::sax_parse<`anonymous-namespace'::sax_lua_tbl_builder>(nlohmann::detail::input_adapter &&,SAX *,nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::input_format_t,const bool)' being compiled
          with
          [
              SAX=`anonymous-namespace'::sax_lua_tbl_builder
          ]
  product\lua_runtime_setup.cpp(464): note: see reference to function template instantiation 'bool nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::sax_parse<`anonymous-namespace'::sax_lua_tbl_builder>(nlohmann::detail::input_adapter &&,SAX *,nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::input_format_t,const bool)' being compiled
          with
          [
              SAX=`anonymous-namespace'::sax_lua_tbl_builder
          ]

As you can probably gather, I have a sax parser:

class sax_lua_tbl_builder : public nlohmann::json::json_sax_t

which I use to convert a JSON document into another form.

For the time being, I have wrapped the header like this:

#pragma warning ( push )
#pragma warning ( disable: 4800 )
#include "../srclibs/json/json.hpp"
#pragma warning ( pop )

since it seems like I can safely ignore it, but I figured you might like to know about the issue to do some sort of proper fix. Especially because this warning was NOT emitted in the previous version (3.3.0).

@nlohmann nlohmann added the platform: visual studio related to MSVC label Nov 19, 2018
@nlohmann
Copy link
Owner

Thanks for reporting! The warnings stems from the BSON parser which was indeed introduced in version 3.4.0.

The line (json.hpp:6585) in question is

return sax->boolean(static_cast<bool>(get()));

and by changing it to

return sax->boolean(get() != 0);

the warning should go away. Strange that it is not displayed in the AppVeyor log.

@ziggurat29 Could you please try whether the proposed change fixes the warning?

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Nov 20, 2018
@ziggurat29
Copy link
Author

ziggurat29 commented Nov 21, 2018 via email

@nlohmann nlohmann self-assigned this Nov 21, 2018
@nlohmann nlohmann added this to the Release 3.4.1 milestone Nov 21, 2018
nlohmann added a commit that referenced this issue Nov 21, 2018
@nlohmann
Copy link
Owner

Thanks for checking back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: visual studio related to MSVC release item: ⚡ improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants