Skip to content

errors in g++-4.8.1 #68

Closed
Closed

Description

@soonhokong

g++-4.8.1 generates the following two errors while g++-4.9.2 does not generate any error (OS: ubuntu-12.04).

g++-4.8 -std=c++11    -I src -I test test/unit.cpp  -o json_unit
In file included from test/unit.cpp:25:0:
src/json.hpp: In instantiation of ‘T nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::erase(T) [with T = nlohmann::basic_json<>::const_iterator; typename std::enable_if<(std::is_same<V, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::iterator>::value || std::is_same<V, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::const_iterator>::value), int>::type <anonymous> = 0; ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’:
test/unit.cpp:2655:80:   required from here
src/json.hpp:1286:44: error: no matching function for call to ‘std::vector<nlohmann::basic_json<> >::erase(__gnu_cxx::__normal_iterator<const nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >&)’
                 result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
                                            ^
src/json.hpp:1286:44: note: candidates are:
In file included from /usr/include/c++/4.8/vector:69:0,
                 from /usr/include/c++/4.8/bits/random.h:34,
                 from /usr/include/c++/4.8/random:50,
                 from /usr/include/c++/4.8/bits/stl_algo.h:65,
                 from /usr/include/c++/4.8/algorithm:62,
                 from test/catch.hpp:62,
                 from test/unit.cpp:11:
/usr/include/c++/4.8/bits/vector.tcc:134:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator) [with _Tp = nlohmann::basic_json<>; _Alloc = std::allocator<nlohmann::basic_json<> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = nlohmann::basic_json<>*]
     vector<_Tp, _Alloc>::
     ^
/usr/include/c++/4.8/bits/vector.tcc:134:5: note:   no known conversion for argument 1 from ‘__gnu_cxx::__normal_iterator<const nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >’ to ‘std::vector<nlohmann::basic_json<> >::iterator {aka __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >}’
/usr/include/c++/4.8/bits/vector.tcc:146:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::iterator) [with _Tp = nlohmann::basic_json<>; _Alloc = std::allocator<nlohmann::basic_json<> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = nlohmann::basic_json<>*]
     vector<_Tp, _Alloc>::
     ^
/usr/include/c++/4.8/bits/vector.tcc:146:5: note:   candidate expects 2 arguments, 1 provided
In file included from test/unit.cpp:25:0:
src/json.hpp: In instantiation of ‘T nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::erase(T, T) [with T = nlohmann::basic_json<>::const_iterator; typename std::enable_if<(std::is_same<V, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::iterator>::value || std::is_same<V, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::const_iterator>::value), int>::type <anonymous> = 0; ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’:
test/unit.cpp:2671:95:   required from here
src/json.hpp:1348:44: error: no matching function for call to ‘std::vector<nlohmann::basic_json<> >::erase(__gnu_cxx::__normal_iterator<const nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >&, __gnu_cxx::__normal_iterator<const nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >&)’
                 result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
                                            ^
src/json.hpp:1348:44: note: candidates are:
In file included from /usr/include/c++/4.8/vector:69:0,
                 from /usr/include/c++/4.8/bits/random.h:34,
                 from /usr/include/c++/4.8/random:50,
                 from /usr/include/c++/4.8/bits/stl_algo.h:65,
                 from /usr/include/c++/4.8/algorithm:62,
                 from test/catch.hpp:62,
                 from test/unit.cpp:11:
/usr/include/c++/4.8/bits/vector.tcc:134:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator) [with _Tp = nlohmann::basic_json<>; _Alloc = std::allocator<nlohmann::basic_json<> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = nlohmann::basic_json<>*]
     vector<_Tp, _Alloc>::
     ^
/usr/include/c++/4.8/bits/vector.tcc:134:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/4.8/bits/vector.tcc:146:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::iterator) [with _Tp = nlohmann::basic_json<>; _Alloc = std::allocator<nlohmann::basic_json<> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = nlohmann::basic_json<>*]
     vector<_Tp, _Alloc>::
     ^
/usr/include/c++/4.8/bits/vector.tcc:146:5: note:   no known conversion for argument 1 from ‘__gnu_cxx::__normal_iterator<const nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >’ to ‘std::vector<nlohmann::basic_json<> >::iterator {aka __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<> > >}’
make: *** [json_unit] Error 1

Activity

  1. nlohmann commented on May 3, 2015

    @nlohmann
    Owner

    Thanks for reporting. I'll have a look soon.

  2. nlohmann commented on May 3, 2015

    @nlohmann
    Owner

    I can reproduce this error with Homebrew gcc48 4.8.4.

  3. self-assigned this
    on May 6, 2015
  4. nlohmann commented on May 6, 2015

    @nlohmann
    Owner

    This is a bug in GCC, see here and here. I see what I can do to circumvent it.

  5. nlohmann commented on May 6, 2015

    @nlohmann
    Owner

    The reason was that std::vector::erase was not implemented for const iterators before GCC 4.9. I could circumvent this in my code.

  6. nlohmann commented on May 6, 2015

    @nlohmann
    Owner

    dreal/DReal.jl#2 and dreal/dreal3#97 - this bug is now fixed; the code compiles with GCC 4.8.

  7. soonhokong commented on May 6, 2015

    @soonhokong
    Author

    @nlohmann, thank you very much!

  8. added a commit that references this issue on Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions