nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
43.25k stars 6.74k forks source link

Compiler Warnings on Raspberry Pi OS #2850

Closed mfvargo closed 3 years ago

mfvargo commented 3 years ago

What is the issue you have?

Compiling on Rapsberry Pi OS creates a large number of warnings. Code seems to still work but it's unnerving. Build on ubuntu produces no warnings. Software on both systems works the same (as far as I can tell)

Here are a first few warnings. They are all similar:

In file included from /usr/include/c++/8/map:61,
                 from json.hpp:61,
                 from cppversion.cpp:2:
/usr/include/c++/8/bits/stl_map.h: In member function ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::__cxx11::basic_string<char>; _Tp = nlohmann::basic_json<>; _Compare = std::less<void>; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, nlohmann::ba
sic_json<> > >]’:
/usr/include/c++/8/bits/stl_map.h:518:8: note: parameter passing for argument of type ‘std::_Rb_tree<std::__cxx11::basic_string<char>, std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<> >, std::_Select1st<std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<> > >, std::less<void>, std::allocator<std::pair<const std::__cxx11::basic_string<char>, nlohmann::ba
sic_json<> > > >::const_iterator’ {aka ‘std::_Rb_tree_const_iterator<std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<> > >’} changed in GCC 7.1
    __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
In file included from /usr/include/c++/8/vector:69,
                 from json.hpp:47,
                 from cppversion.cpp:2:
/usr/include/c++/8/bits/vector.tcc: In member function ‘void std::vector<_Tp, _Alloc>::reserve(std::vector<_Tp, _Alloc>::size_type) [with _Tp = nlohmann::basic_json<>; _Alloc = std::allocator<nlohmann::basic_json<> >]’:
/usr/include/c++/8/bits/vector.tcc:74:12: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1
    pointer __tmp = _M_allocate_and_copy(__n,
            ^~~~~

Please describe the steps to reproduce the issue.

Compile this source code (cppversion.cpp)

#include<iostream>
#include "json.hpp"

using json = nlohmann::json;

int main() {
  json myjson;
  myjson["key"] = "value";
  std::cout << myjson.dump(2) << std::endl;
  if (__cplusplus == 201703L) std::cout << "C++17\n";
  else if (__cplusplus == 201402L) std::cout << "C++14\n";
  else if (__cplusplus == 201103L) std::cout << "C++11\n";
  else if (__cplusplus == 199711L) std::cout << "C++98\n";
  else std::cout << "pre-standard C++\n";
}

with this command build code

gcc -lstdc++ cppversion.cpp

Program Output ( ./a.out )

{
  "key": "value"
}
C++14

What is the expected behavior?

It should compile with no warnings.

And what is the actual behavior instead?

You get a ton of warnings.

Which compiler and operating system are you using?

cat /etc/os-release on Pi

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

gcc -version on Pi

gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
Copyright (C) 2018 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.

Which version of the library did you use?

Licensed under the MIT License http://opensource.org/licenses/MIT. SPDX-License-Identifier: MIT Copyright (c) 2013-2019 Niels Lohmann http://nlohmann.me.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */


#### If you experience a compilation error: can you [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests)?

- [ ] yes
- [x] no - please copy/paste the error message below

full compile output log

In file included from /usr/include/c++/8/map:61, from json.hpp:61, from cppversion.cpp:2: /usr/include/c++/8/bits/stl_map.h: In member function ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::cxx11::basic_string; _Tp = nlohmann::basic_json<>; _Compare = std::less; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string, nlohmann::basic_json<> > >]’: /usr/include/c++/8/bits/stl_map.h:518:8: note: parameter passing for argument of type ‘std::_Rb_tree<std::cxx11::basic_string, std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> >, std::_Select1st<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >, std::less, std::allocator<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > > >::const_iterator’ {aka ‘std::_Rb_tree_const_iterator<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >’} changed in GCC 7.1 i = _M_t._M_emplace_hint_unique(i, std::piecewise_construct, In file included from /usr/include/c++/8/vector:69, from json.hpp:47, from cppversion.cpp:2: /usr/include/c++/8/bits/vector.tcc: In member function ‘void std::vector<_Tp, _Alloc>::reserve(std::vector<_Tp, _Alloc>::size_type) [with _Tp = nlohmann::basic_json<>; _Alloc = std::allocator<nlohmann::basic_json<> >]’: /usr/include/c++/8/bits/vector.tcc:74:12: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>>’ changed in GCC 7.1 pointer tmp = _M_allocate_and_copy(n, ^~~~~ In file included from /usr/include/c++/8/map:60, from json.hpp:61, from cppversion.cpp:2: /usr/include/c++/8/bits/stl_tree.h: In member function ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_emplace_hint_unique(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<std::cxx11::basic_string<char, std::char_traits, std::allocator >&&>, std::tuple<>}; _Key = std::cxx11::basic_string; _Val = std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> >; _KeyOfValue = std::_Select1st<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >; _Compare = std::less; _Alloc = std::allocator<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >]’: /usr/include/c++/8/bits/stl_tree.h:2411:7: note: parameter passing for argument of type ‘std::_Rb_tree<std::cxx11::basic_string, std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> >, std::_Select1st<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >, std::less, std::allocator<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > > >::const_iterator’ {aka ‘std::_Rb_tree_const_iterator<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >’} changed in GCC 7.1 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: ^~~~~~~~~~~ In file included from /usr/include/c++/8/bits/stl_algobase.h:66, from /usr/include/c++/8/bits/char_traits.h:39, from /usr/include/c++/8/ios:40, from /usr/include/c++/8/ostream:38, from /usr/include/c++/8/iostream:39, from cppversion.cpp:1: /usr/include/c++/8/bits/stl_iterator_base_funcs.h: In function ‘_InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type) [with _InputIterator = std::_Rb_tree_const_iterator<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >]’: /usr/include/c++/8/bits/stl_iterator_base_funcs.h:213:5: note: parameter passing for argument of type ‘std::_Rb_tree_const_iterator<std::pair<const std::__cxx11::basic_string, nlohmann::basic_json<> > >’ changed in GCC 7.1 next(_InputIterator x, typename ^~~~ In file included from /usr/include/c++/8/vector:64, from json.hpp:47, from cppversion.cpp:2: /usr/include/c++/8/bits/stl_vector.h: In member function ‘std::vector<_Tp, _Alloc>::pointer std::vector<_Tp, _Alloc>::_M_allocate_and_copy(std::vector<_Tp, _Alloc>::size_type, _ForwardIterator, _ForwardIterator) [with _ForwardIterator = std::move_iterator<nlohmann::basic_json<>>; _Tp = nlohmann::basic_json<>; _Alloc = std::allocator<nlohmann::basic_json<> >]’: /usr/include/c++/8/bits/stl_vector.h:1395:2: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>>’ changed in GCC 7.1 _M_allocate_and_copy(size_type __n, ^~~~~~~~ /usr/include/c++/8/bits/stl_vector.h:1395:2: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>>’ changed in GCC 7.1 /usr/include/c++/8/bits/stl_vector.h:1401:35: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1 std::uninitialized_copy_a(first, last, result,

        _M_get_Tp_allocator());

In file included from /usr/include/c++/8/map:60, from json.hpp:61, from cppversion.cpp:2: /usr/include/c++/8/bits/stl_tree.h: In member function ‘std::pair<std::_Rb_tree_node_base, std::_Rb_tree_node_base> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_hint_unique_pos(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator, const key_type&) [with _Key = std::cxx11::basic_string; _Val = std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> >; _KeyOfValue = std::_Select1st<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >; _Compare = std::less; _Alloc = std::allocator<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >]’: /usr/include/c++/8/bits/stl_tree.h:2146:5: note: parameter passing for argument of type ‘std::_Rb_tree<std::cxx11::basic_string, std::pair<const std::__cxx11::basic_string, nlohmann::basic_json<> >, std::_Select1st<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > >, std::less, std::allocator<std::pair<const std::cxx11::basic_string, nlohmann::basic_json<> > > >::const_iterator’ {aka ‘std::_Rb_tree_const_iterator<std::pair<const std::__cxx11::basic_string, nlohmann::basic_json<> > >’} changed in GCC 7.1 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: ^~~~~~~~~~~ In file included from /usr/include/c++/8/memory:65, from json.hpp:43, from cppversion.cpp:2: /usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<nlohmann::basic_json<>>; _ForwardIterator = nlohmann::basic_json<>; _Tp = nlohmann::basic_json<>]’: /usr/include/c++/8/bits/stl_uninitialized.h:287:5: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>>’ changed in GCC 7.1 uninitialized_copy_a(_InputIterator __first, _InputIterator last, ^~~~~~ /usr/include/c++/8/bits/stl_uninitialized.h:287:5: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>>’ changed in GCC 7.1 /usr/include/c++/8/bits/stl_uninitialized.h:289:37: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1 { return std::uninitialized_copy(first, last, __result); }

/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<nlohmann::basic_json<>*>; _ForwardIterator = nlohmann::basic_json<>*]’:
/usr/include/c++/8/bits/stl_uninitialized.h:115:5: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1
     uninitialized_copy(_InputIterator __first, _InputIterator __last,
     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:115:5: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:134:15: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1
       return std::__uninitialized_copy<__is_trivial(_ValueType1)
        && __is_trivial(_ValueType2)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        && __assignable>::
        ~~~~~~~~~~~~~~~~~~

__uninit_copy(first, last, __result);

/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = nlohmann::basic_json<>*; _ForwardIterator = nlohmann::basic_json<>*; _Allocator = std::allocator<nlohmann::basic_json<> >]’:
/usr/include/c++/8/bits/stl_uninitialized.h:311:2: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1
       return std::__uninitialized_copy_a

(_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(first), ^~~~~~~~~~~~~~ _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(last), result, alloc);


/usr/include/c++/8/bits/stl_uninitialized.h: In static member function ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<nlohmann::basic_json<>*>; _ForwardIterator = nlohmann::basic_json<>*; bool _TrivialValueTypes = false]’:
/usr/include/c++/8/bits/stl_uninitialized.h:76:9: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1
         __uninit_copy(_InputIterator __first, _InputIterator __last,
         ^~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:76:9: note: parameter passing for argument of type ‘std::move_iterator<nlohmann::basic_json<>*>’ changed in GCC 7.1

```
nlohmann commented 3 years ago

Duplicate #1861, see https://github.com/nlohmann/json/issues/1861#issuecomment-745998713.

The gist: this is not an issue in the library, but a note from GCC. You can ignore the warning or upgrade your GCC.

mfvargo commented 3 years ago

Thank you. sorry to open a duplicate issue.

nlohmann commented 3 years ago

No worries! Maybe it’s time to put this into an FAQ.