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

insert json array issue with gcc4.8.2 #110

Closed
exppii opened this issue Aug 11, 2015 · 5 comments
Closed

insert json array issue with gcc4.8.2 #110

exppii opened this issue Aug 11, 2015 · 5 comments
Assignees
Labels
confirmed kind: bug solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope)

Comments

@exppii
Copy link

exppii commented Aug 11, 2015

The task may like this:

[
{
 "id" : "1111-0000",
"content" : []
},
{
 "id" : "1111-2222",
"content" : []
}
]

when I try to insert json to _task

 // nlohmann::json _task; 
  void add_task(const nlohmann::json& tasks) {
    std::lock_guard<std::mutex> lock(_mtx);
    _task.insert(_task.end(),tasks.cbegin(),tasks.cend());
  }

I get this error when using gcc4.8.2 (but worked when using clang3.6)

home/sven/Workspace/Collector/include/json.hpp: In instantiation of ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::iterator nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::insert(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::const_iterator, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::const_iterator, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::const_iterator) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberFloatType = double; AllocatorType = std::allocator]’:
/home/sven/Workspace/Collector/Collector/Services/serialize_manager.cpp:46:57:   required from here
/home/sven/Workspace/Collector/include/json.hpp:3897:36: error: no match for ‘operator=’ (operand types are ‘std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > >::iterator {aka __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >}’ and ‘void’)
         result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator,
                                    ^
/home/sven/Workspace/Collector/include/json.hpp:3897:36: note: candidates are:
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/4.8.2/bits/char_traits.h:39,
                 from /usr/include/c++/4.8.2/string:40,
                 from /home/sven/Workspace/Collector/Collector/Services/serialize_manager.h:8,
                 from /home/sven/Workspace/Collector/Collector/Services/serialize_manager.cpp:5:
/usr/include/c++/4.8.2/bits/stl_iterator.h:708:11: note: __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >& __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >::operator=(const __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >&)
     class __normal_iterator
           ^
/usr/include/c++/4.8.2/bits/stl_iterator.h:708:11: note:   no known conversion for argument 1 from ‘void’ to ‘const __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >&’
/usr/include/c++/4.8.2/bits/stl_iterator.h:708:11: note: __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >& __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >::operator=(__gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >&&)
/usr/include/c++/4.8.2/bits/stl_iterator.h:708:11: note:   no known conversion for argument 1 from ‘void’ to ‘__gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >&&’
gmake[3]: *** [Collector/CMakeFiles/collector.dir/Services/serialize_manager.cpp.o] Error 1
gmake[2]: *** [Collector/CMakeFiles/collector.dir/all] Error 2
gmake[1]: *** [Collector/CMakeFiles/collector.dir/rule] Error 2
gmake: *** [collector] Error 2
@nlohmann nlohmann self-assigned this Aug 11, 2015
@nlohmann
Copy link
Owner

Thanks for reporting. I'll see if I can reproduce the error.

@wasphin
Copy link

wasphin commented Dec 8, 2015

$ g++ --version
g++ (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

no that interface in /usr/include/c++/4.8.3/bits/stl_vector.h

@gregmarr
Copy link
Contributor

gregmarr commented Dec 8, 2015

Looks like you're using a C++98 library instead of a C++11 library. The return type of std::vector::insert taking 3 iterators changed from void to iterator in C++11.

@nlohmann
Copy link
Owner

nlohmann commented Dec 8, 2015

I can reproduce the error with

g++-4.8 (Homebrew gcc48 4.8.4) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

For code

#include <json.hpp>

nlohmann::json _task; 

void add_task(const nlohmann::json& tasks) {
    _task.insert(_task.end(),tasks.cbegin(),tasks.cend());
}

int main() {
}

I get the following error:

In file included from issue110.cpp:1:0:
src/json.hpp: In instantiation of 'nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::iterator nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::insert(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::const_iterator, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::const_iterator, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::const_iterator) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long long int; NumberFloatType = double; AllocatorType = std::allocator]':
issue110.cpp:6:57:   required from here
src/json.hpp:3899:36: error: no match for 'operator=' (operand types are 'std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > >::iterator {aka __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >}' and 'void')
         result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator,
                                    ^
src/json.hpp:3899:36: note: candidates are:
In file included from /usr/local/homebrew/Cellar/gcc48/4.8.4/include/c++/4.8.4/bits/stl_algobase.h:67:0,
                 from /usr/local/homebrew/Cellar/gcc48/4.8.4/include/c++/4.8.4/algorithm:61,
                 from src/json.hpp:41,
                 from issue110.cpp:1:
/usr/local/homebrew/Cellar/gcc48/4.8.4/include/c++/4.8.4/bits/stl_iterator.h:708:11: note: __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >& __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >::operator=(const __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >&)
     class __normal_iterator
           ^
/usr/local/homebrew/Cellar/gcc48/4.8.4/include/c++/4.8.4/bits/stl_iterator.h:708:11: note:   no known conversion for argument 1 from 'void' to 'const __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >&'
/usr/local/homebrew/Cellar/gcc48/4.8.4/include/c++/4.8.4/bits/stl_iterator.h:708:11: note: __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >& __gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >::operator=(__gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >&&)
/usr/local/homebrew/Cellar/gcc48/4.8.4/include/c++/4.8.4/bits/stl_iterator.h:708:11: note:   no known conversion for argument 1 from 'void' to '__gnu_cxx::__normal_iterator<nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >&&'
make: *** [issue110] Error 1

This seems to be the same.

@nlohmann
Copy link
Owner

nlohmann commented Dec 8, 2015

This is a bug in GCC, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55817. It has not been fixed until GCC 4.9. I shall edit file README and remove GCC 4.8 support.

nlohmann added a commit that referenced this issue Dec 8, 2015
@nlohmann nlohmann closed this as completed Dec 8, 2015
@nlohmann nlohmann added the solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope) label Dec 8, 2015
@ZahlGraf ZahlGraf mentioned this issue Jan 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope)
Projects
None yet
Development

No branches or pull requests

4 participants