Skip to content

-Wconversion warning #259

Closed
Closed

Description

@miporto

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

  1. nlohmann commented on Jun 4, 2016

    @nlohmann
    Owner

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

  2. miporto commented on Jun 4, 2016

    @miporto
    Author

    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());
                     ^
    
  3. nlohmann commented on Jun 4, 2016

    @nlohmann
    Owner

    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?

  4. nlohmann commented on Jun 4, 2016

    @nlohmann
    Owner

    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.)

  5. added
    solution: invalid
    on Jun 4, 2016
  6. miporto commented on Jun 4, 2016

    @miporto
    Author

    Ok, thanks for your help!

  7. guygman commented on Jun 20, 2016

    @guygman

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

  8. nlohmann commented on Jun 20, 2016

    @nlohmann
    Owner

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

  9. added and removed
    solution: invalid
    on Jun 20, 2016
  10. guygman commented on Jun 21, 2016

    @guygman

    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

  11. nlohmann commented on Jun 22, 2016

    @nlohmann
    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?

  12. added this to the Release 2.0.0 milestone on Jun 22, 2016
  13. added
    state: please discuss
    on Jun 22, 2016
  14. guygman commented on Jun 23, 2016

    @guygman

    Hi,

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

  15. nlohmann commented on Jun 23, 2016

    @nlohmann
    Owner

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

  16. removed
    state: please discuss
    on Jun 23, 2016
  17. added a commit that references this issue on Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions