Repository navigation
Closed
Labels
Milestone
Description
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
Activity
nlohmann commentedon Jun 4, 2016
Could you please try the latest version in the
developbranch? I remember fixing some conversion warnings there.miporto commentedon Jun 4, 2016
I tried with the
developversion, but now I receive an error that didn't appear with the release library.nlohmann commentedon 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 commentedon 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.)
miporto commentedon Jun 4, 2016
Ok, thanks for your help!
guygman commentedon 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 commentedon Jun 20, 2016
This is very strange. Can you please provide the concrete warning output?
guygman commentedon Jun 21, 2016
here's the build output.
the error is at the point of instantiation of a class with an nlohmann::json member.
nlohmann commentedon Jun 22, 2016
Hi @guygman, thanks for providing more information. It seems as if Clang is choking on an implicit conversion from
type_data_ttobasic_json. In fact, I am planning to removetype_data_taltogether - could you please try to compile your example with this branch?guygman commentedon Jun 23, 2016
Hi,
compiling with that branch worked much better! there was no conversion error.
nlohmann commentedon Jun 23, 2016
That branch has now been merge with develop, see f86fe57 .
hotfix for gcc/4.8.x