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

-Wconversion warning #259

Closed
miporto opened this issue Jun 4, 2016 · 11 comments
Closed

-Wconversion warning #259

miporto opened this issue Jun 4, 2016 · 11 comments

Comments

@miporto
Copy link

miporto commented Jun 4, 2016

I'm receiving a -Wconversion warning when including and compiling the latest release of the library. I read #239 but the errors showed are different (although it's the same flag that sends the warning), also the links present there are down.
Here is the complete output:

In file included from .../foo.cpp:3:0:
.../json.hpp: In instantiation of ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, 
BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::escape_string(const 
string_t&) [with ObjectType = std::map; ArrayType = std::vector; StringType = 
std::basic_string<char>; BooleanType = bool; NumberInteger
Type = long int; NumberFloatType = double; AllocatorType = std::allocator; 
nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, 
NumberFloatType, AllocatorType>::string_t = std::basic_string<char>]::__lambda3’:
.../json.hpp:5455:40:   required from ‘struct nlohmann::basic_json<ObjectType, ArrayType, 
StringType, BooleanType, NumberIntegerType, NumberFloatType, 
AllocatorType>::escape_string(const string_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>]::__lambda3’
.../json.hpp:5458:25:   required from ‘static nlohmann::basic_json<ObjectType, ArrayType, 
StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t 
nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, 
NumberFloatType, AllocatorType>::escape_string(const string_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>]’
.../json.hpp:5536:48:   required from ‘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>]’
.../json.hpp:1892:61:   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>]’
.../json.hpp:8209:25:   required from here
.../json.hpp:5457:72: error: conversion to ‘char’ from ‘int’ may alter its value [-Werror=conversion]
                             return (v < 10) ? ('0' + v) : ('a' + v - 10);
                                                                        ^
.../json.hpp:5457:72: error: conversion to ‘char’ from ‘int’ may alter its value [-Werror=conversion]
.../json.hpp: In instantiation of ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, 
BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::string_t 
nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, 
NumberFloatType, AllocatorType>::escape_string(const
 string_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>]’:
.../json.hpp:5536:48:   required from ‘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>]’
.../json.hpp:1892:61:   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>]’
.../json.hpp:8209:25:   required from here
.../json.hpp:5462:51: error: conversion to ‘char’ from ‘int’ may alter its value [-Werror=conversion]
                     { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f)
                                                   ^
cc1plus: all warnings being treated as errors
  • gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
  • Compile flags: -std=c++11 -Wall -Werror -Wconversion -Wno-unused-parameter -Wextra -Wtype-limits -pedantic -pedantic-errors
@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2016

Could you please try the latest version in the develop branch? I remember fixing some conversion warnings there.

@miporto
Copy link
Author

miporto commented Jun 4, 2016

I tried with the develop version, but now I receive an error that didn't appear with the release library.

In file included from .../foo.cpp:6:0:
.../json.hpp: In instantiation of 
‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, 
NumberUnsignedType, NumberFloatType, AllocatorType>::value_type& 
nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, 
NumberUnsignedType, NumberFloatType, AllocatorType>::operator[]
(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, 
NumberUnsignedType, NumberFloatType, AllocatorType>::size_type) [with ObjectType = std::map; 
ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; 
NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = 
double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, 
BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, 
AllocatorType>::reference = nlohmann::basic_json<>&; nlohmann::basic_json<ObjectType, 
ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, 
NumberFloatType, AllocatorType>::value_type = nlohmann::basic_json<>; 
nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, 
NumberUnsignedType, NumberFloatType, AllocatorType>::size_type = long unsigned int]’:
.../foo.cpp:21:49:   required from here
.../json.hpp:1062:5: error: conversion from 
‘nlohmann::basic_json<>::value_t’ to non-scalar type ‘nlohmann::basic_json<>::type_data_t’ 
requested
     basic_json() = default;
     ^
.../json.hpp:3307:17: note: synthesized method ‘nlohmann::basic_json<ObjectType, ArrayType, 
StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, 
AllocatorType>::basic_json() [with ObjectType = std::map; ArrayType = std::vector; StringType = 
std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType 
= long unsigned int; NumberFloatType = double; AllocatorType = std::allocator]’ first required here 
                 m_value.array->push_back(basic_json());
                 ^

@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2016

This is a known error of GCC 4.8 which is therefore not supported by the library, see https://github.com/nlohmann/json#supported-compilers. Can you try with a more recent compiler?

@nlohmann
Copy link
Owner

nlohmann commented Jun 4, 2016

I had another look at your first output. These warnings have been fixed with #239 (see commit db5c9ec). (The links are down, because the feature branch has been merged and deleted since.)

@nlohmann nlohmann closed this as completed Jun 4, 2016
@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Jun 4, 2016
@miporto
Copy link
Author

miporto commented Jun 4, 2016

Ok, thanks for your help!

@guygman
Copy link

guygman commented Jun 20, 2016

Hi, I'm running into the same issue, but with commit 15a314a.
I'm using Clang 3.4.2 for Linux

@nlohmann
Copy link
Owner

This is very strange. Can you please provide the concrete warning output?

@nlohmann nlohmann added kind: bug and removed solution: invalid the issue is not related to the library labels Jun 20, 2016
@nlohmann nlohmann reopened this Jun 20, 2016
@guygman
Copy link

guygman commented Jun 21, 2016

here's the build output.
the error is at the point of instantiation of a class with an nlohmann::json member.

[ 91%] Building CXX object common/CMakeFiles/common.dir/config.cpp.o
In file included from /home/centos/shared/src_master_origin/common/config.h:8:0,
from /home/centos/shared/src_master_origin/common/config.cpp:1:
/home/centos/shared/src_master_origin/common/../3rdparty/json/src/json.hpp: In instantiation of 'nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType>::parser::parse() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator]':
/home/centos/shared/src_master_origin/common/../3rdparty/json/src/json.hpp:5722:36: required from 'static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType>::parse(const string_t&, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType>::parser_callback_t) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType>::string_t = std::basic_string; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType>::parser_callback_t = std::function<bool(int, nlohmann::basic_json<>::parse_event_t, nlohmann::basic_json<>&)>]'
/home/centos/shared/src_master_origin/common/../3rdparty/json/src/json.hpp:8920:98: required from here
/home/centos/shared/src_master_origin/common/../3rdparty/json/src/json.hpp:1060:5: error: conversion from 'nlohmann::basic_json<>::value_t' to non-scalar type 'nlohmann::basic_json<>::type_data_t' requested
basic_json() = default;
^
/home/centos/shared/src_master_origin/common/../3rdparty/json/src/json.hpp:8611:42: note: synthesized method 'nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType>::basic_json() [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator]' first required here
return result.is_discarded() ? basic_json() : result;
^
make[2]: *** [common/CMakeFiles/common.dir/config.cpp.o] Error 1

@nlohmann
Copy link
Owner

Hi @guygman, thanks for providing more information. It seems as if Clang is choking on an implicit conversion from type_data_t to basic_json. In fact, I am planning to remove type_data_t altogether - could you please try to compile your example with this branch?

@nlohmann nlohmann added this to the Release 2.0.0 milestone Jun 22, 2016
@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Jun 22, 2016
@guygman
Copy link

guygman commented Jun 23, 2016

Hi,

compiling with that branch worked much better! there was no conversion error.

@nlohmann
Copy link
Owner

That branch has now been merge with develop, see f86fe57 .

@nlohmann nlohmann removed the state: please discuss please discuss the issue or vote for your favorite option label Jun 23, 2016
mhsieh pushed a commit to PacificBiosciences/pbcopper that referenced this issue Sep 20, 2016
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