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

"incomplete type ‘nlohmann::detail::wide_string_input_helper" compilation error #2969

Closed
2 of 3 tasks
slhck opened this issue Aug 24, 2021 · 4 comments
Closed
2 of 3 tasks
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@slhck
Copy link

slhck commented Aug 24, 2021

What is the issue you have?

I am using this code to parse lines of JSON (basically stemming from a newline-delimited JSON file) into a vector, then parsing that vector into a JSON array.

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

using json = nlohmann::json;

int main(int argc, char **argv)
{
  std::vector<json> foo_vec;
  foo_vec.push_back(json::parse("{\"foo\": \"bar\"}"));
  foo_vec.push_back(json::parse("{\"baz\": \"baz\"}"));
  std::cout << json::parse(foo_vec) << std::endl;
}

This used to work fine. For some reason (Compiler update? I honestly have no idea), the following compiler error is now raised when compiling:

/test/../include/json.hpp:5627:67: error: incomplete type ‘nlohmann::detail::wide_string_input_helper<nlohmann::detail::iterator_input_adapter<__gnu_cxx::__normal_iterator<const nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > > >, 16>’ used in nested name specifier

The entire log can be found below.

CMake log
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /home/werner/.pyenv/shims/python3.8 (found version "3.8.1") found components: Interpreter 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /build
/usr/bin/cmake -S/home/werner/Documents/Projects/aveq/surfmeter/android-packet-capture/androidpacketcapture/libs/capture-utils -B/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /build/CMakeFiles /build/CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/build'
/usr/bin/make -f src/CMakeFiles/captureutils.dir/build.make src/CMakeFiles/captureutils.dir/depend
make[2]: Entering directory '/build'
cd /build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/werner/Documents/Projects/aveq/surfmeter/android-packet-capture/androidpacketcapture/libs/capture-utils /src /build /build/src /build/src/CMakeFiles/captureutils.dir/DependInfo.cmake --color=
Scanning dependencies of target captureutils
make[2]: Leaving directory '/build'
/usr/bin/make -f src/CMakeFiles/captureutils.dir/build.make src/CMakeFiles/captureutils.dir/build
make[2]: Entering directory '/build'
[  7%] Building CXX object src/CMakeFiles/captureutils.dir/capture_utils.cpp.o
cd /build/src && /usr/bin/c++   -I/src/../include -I/usr/local/include/pcapplusplus  -std=gnu++17 -o CMakeFiles/captureutils.dir/capture_utils.cpp.o -c /src/capture_utils.cpp
[ 15%] Linking CXX static library libcaptureutils.a
cd /build/src && /usr/bin/cmake -P CMakeFiles/captureutils.dir/cmake_clean_target.cmake
cd /build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/captureutils.dir/link.txt --verbose=1
/usr/bin/ar qc libcaptureutils.a  CMakeFiles/captureutils.dir/capture_utils.cpp.o
/usr/bin/ranlib libcaptureutils.a
make[2]: Leaving directory '/build'
[ 15%] Built target captureutils
/usr/bin/make -f _deps/googletest-build/googletest/CMakeFiles/gtest.dir/build.make _deps/googletest-build/googletest/CMakeFiles/gtest.dir/depend
make[2]: Entering directory '/build'
cd /build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/werner/Documents/Projects/aveq/surfmeter/android-packet-capture/androidpacketcapture/libs/capture-utils /build/_deps/googletest-src/googletest /build /build/_deps/googletest-build/googletest /build/_deps/googletest-build/googletest/CMakeFiles/gtest.dir/DependInfo.cmake --color=
Scanning dependencies of target gtest
make[2]: Leaving directory '/build'
/usr/bin/make -f _deps/googletest-build/googletest/CMakeFiles/gtest.dir/build.make _deps/googletest-build/googletest/CMakeFiles/gtest.dir/build
make[2]: Entering directory '/build'
[ 23%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
cd /build/_deps/googletest-build/googletest && /usr/bin/c++   -I/build/_deps/googletest-src/googletest/include -I/build/_deps/googletest-src/googletest  -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -std=c++17 -o CMakeFiles/gtest.dir/src/gtest-all.cc.o -c /build/_deps/googletest-src/googletest/src/gtest-all.cc
[ 30%] Linking CXX static library ../../../lib/libgtest.a
cd /build/_deps/googletest-build/googletest && /usr/bin/cmake -P CMakeFiles/gtest.dir/cmake_clean_target.cmake
cd /build/_deps/googletest-build/googletest && /usr/bin/cmake -E cmake_link_script CMakeFiles/gtest.dir/link.txt --verbose=1
/usr/bin/ar qc ../../../lib/libgtest.a  CMakeFiles/gtest.dir/src/gtest-all.cc.o
/usr/bin/ranlib ../../../lib/libgtest.a
make[2]: Leaving directory '/build'
[ 30%] Built target gtest
/usr/bin/make -f _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/build.make _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/depend
make[2]: Entering directory '/build'
cd /build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/werner/Documents/Projects/aveq/surfmeter/android-packet-capture/androidpacketcapture/libs/capture-utils /build/_deps/googletest-src/googlemock /build /build/_deps/googletest-build/googlemock /build/_deps/googletest-build/googlemock/CMakeFiles/gmock.dir/DependInfo.cmake --color=
Scanning dependencies of target gmock
make[2]: Leaving directory '/build'
/usr/bin/make -f _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/build.make _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/build
make[2]: Entering directory '/build'
[ 38%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
cd /build/_deps/googletest-build/googlemock && /usr/bin/c++   -I/build/_deps/googletest-src/googlemock/include -I/build/_deps/googletest-src/googlemock -isystem /build/_deps/googletest-src/googletest/include -isystem /build/_deps/googletest-src/googletest  -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -std=c++17 -o CMakeFiles/gmock.dir/src/gmock-all.cc.o -c /build/_deps/googletest-src/googlemock/src/gmock-all.cc
[ 46%] Linking CXX static library ../../../lib/libgmock.a
cd /build/_deps/googletest-build/googlemock && /usr/bin/cmake -P CMakeFiles/gmock.dir/cmake_clean_target.cmake
cd /build/_deps/googletest-build/googlemock && /usr/bin/cmake -E cmake_link_script CMakeFiles/gmock.dir/link.txt --verbose=1
/usr/bin/ar qc ../../../lib/libgmock.a  CMakeFiles/gmock.dir/src/gmock-all.cc.o
/usr/bin/ranlib ../../../lib/libgmock.a
make[2]: Leaving directory '/build'
[ 46%] Built target gmock
/usr/bin/make -f _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/build.make _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/depend
make[2]: Entering directory '/build'
cd /build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/werner/Documents/Projects/aveq/surfmeter/android-packet-capture/androidpacketcapture/libs/capture-utils /build/_deps/googletest-src/googletest /build /build/_deps/googletest-build/googletest /build/_deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/DependInfo.cmake --color=
Scanning dependencies of target gtest_main
make[2]: Leaving directory '/build'
/usr/bin/make -f _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/build.make _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/build
make[2]: Entering directory '/build'
[ 53%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
cd /build/_deps/googletest-build/googletest && /usr/bin/c++   -isystem /build/_deps/googletest-src/googletest/include -isystem /build/_deps/googletest-src/googletest  -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -std=c++17 -o CMakeFiles/gtest_main.dir/src/gtest_main.cc.o -c /build/_deps/googletest-src/googletest/src/gtest_main.cc
[ 61%] Linking CXX static library ../../../lib/libgtest_main.a
cd /build/_deps/googletest-build/googletest && /usr/bin/cmake -P CMakeFiles/gtest_main.dir/cmake_clean_target.cmake
cd /build/_deps/googletest-build/googletest && /usr/bin/cmake -E cmake_link_script CMakeFiles/gtest_main.dir/link.txt --verbose=1
/usr/bin/ar qc ../../../lib/libgtest_main.a  CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
/usr/bin/ranlib ../../../lib/libgtest_main.a
make[2]: Leaving directory '/build'
[ 61%] Built target gtest_main
/usr/bin/make -f test/CMakeFiles/test_captureutils.dir/build.make test/CMakeFiles/test_captureutils.dir/depend
make[2]: Entering directory '/build'
cd /build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/werner/Documents/Projects/aveq/surfmeter/android-packet-capture/androidpacketcapture/libs/capture-utils /test /build /build/test /build/test/CMakeFiles/test_captureutils.dir/DependInfo.cmake --color=
Scanning dependencies of target test_captureutils
make[2]: Leaving directory '/build'
/usr/bin/make -f test/CMakeFiles/test_captureutils.dir/build.make test/CMakeFiles/test_captureutils.dir/build
make[2]: Entering directory '/build'
[ 69%] Building CXX object test/CMakeFiles/test_captureutils.dir/__/src/capture_utils.cpp.o
cd /build/test && /usr/bin/c++   -I/test/../include -I/usr/local/include/pcapplusplus -isystem /build/_deps/googletest-src/googletest/include -isystem /build/_deps/googletest-src/googletest -isystem /build/_deps/googletest-src/googlemock/include -isystem /build/_deps/googletest-src/googlemock  -std=gnu++17 -o CMakeFiles/test_captureutils.dir/__/src/capture_utils.cpp.o -c /src/capture_utils.cpp
[ 76%] Building CXX object test/CMakeFiles/test_captureutils.dir/test_captureutils.cpp.o
cd /build/test && /usr/bin/c++   -I/test/../include -I/usr/local/include/pcapplusplus -isystem /build/_deps/googletest-src/googletest/include -isystem /build/_deps/googletest-src/googletest -isystem /build/_deps/googletest-src/googlemock/include -isystem /build/_deps/googletest-src/googlemock  -std=gnu++17 -o CMakeFiles/test_captureutils.dir/test_captureutils.cpp.o -c /test/test_captureutils.cpp
In file included from /test/test_captureutils.cpp:2:
/test/../include/json.hpp: In instantiation of ‘void nlohmann::detail::wide_string_input_adapter::fill_buffer() [with long unsigned int T = 16; BaseInputAdapter = nlohmann::detail::iterator_input_adapter<__gnu_cxx::__normal_iterator*, std::vector, std::allocator > > > >; WideCharType = nlohmann::basic_json<>]’:
/test/../include/json.hpp:5609:46:   required from ‘std::char_traits::int_type nlohmann::detail::wide_string_input_adapter::get_character() [with BaseInputAdapter = nlohmann::detail::iterator_input_adapter<__gnu_cxx::__normal_iterator*, std::vector, std::allocator > > > >; WideCharType = nlohmann::basic_json<>; std::char_traits::int_type = int]’
/test/../include/json.hpp:7851:39:   required from ‘nlohmann::detail::lexer::char_int_type nlohmann::detail::lexer::get() [with BasicJsonType = nlohmann::basic_json<>; InputAdapterType = nlohmann::detail::wide_string_input_adapter*, std::vector, std::allocator > > > >, nlohmann::basic_json<> >; nlohmann::detail::lexer::char_int_type = int]’
/test/../include/json.hpp:7990:13:   required from ‘bool nlohmann::detail::lexer::skip_bom() [with BasicJsonType = nlohmann::basic_json<>; InputAdapterType = nlohmann::detail::wide_string_input_adapter*, std::vector, std::allocator > > > >, nlohmann::basic_json<> >]’
/test/../include/json.hpp:8014:48:   required from ‘nlohmann::detail::lexer::token_type nlohmann::detail::lexer::scan() [with BasicJsonType = nlohmann::basic_json<>; InputAdapterType = nlohmann::detail::wide_string_input_adapter*, std::vector, std::allocator > > > >, nlohmann::basic_json<> >; nlohmann::detail::lexer::token_type = nlohmann::detail::lexer_base >::token_type]’
/test/../include/json.hpp:11262:41:   required from ‘nlohmann::detail::parser::token_type nlohmann::detail::parser::get_token() [with BasicJsonType = nlohmann::basic_json<>; InputAdapterType = nlohmann::detail::wide_string_input_adapter*, std::vector, std::allocator > > > >, nlohmann::basic_json<> >; nlohmann::detail::parser::token_type = nlohmann::detail::lexer_base >::token_type]’
/test/../include/json.hpp:10900:28:   required from ‘void nlohmann::detail::parser::parse(bool, BasicJsonType&) [with BasicJsonType = nlohmann::basic_json<>; InputAdapterType = nlohmann::detail::wide_string_input_adapter*, std::vector, std::allocator > > > >, nlohmann::basic_json<> >]’
/test/../include/json.hpp:24253:111:   required from ‘static nlohmann::basic_json nlohmann::basic_json::parse(InputType&&, nlohmann::basic_json::parser_callback_t, bool, bool) [with InputType = std::vector, std::allocator > >&; ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector; nlohmann::basic_json::parser_callback_t = std::function&)>]’
/test/test_captureutils.cpp:11:35:   required from here
/test/../include/json.hpp:5627:67: error: incomplete type ‘nlohmann::detail::wide_string_input_helper*, std::vector, std::allocator > > > >, 16>’ used in nested name specifier
 5627 |         wide_string_input_helper::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [test/CMakeFiles/test_captureutils.dir/build.make:79: test/CMakeFiles/test_captureutils.dir/test_captureutils.cpp.o] Error 1
make[2]: Leaving directory '/build'
make[1]: *** [CMakeFiles/Makefile2:209: test/CMakeFiles/test_captureutils.dir/all] Error 2
make[1]: Leaving directory '/build'
make: *** [Makefile:144: all] Error 2

Please describe the steps to reproduce the issue.

See above.

Which compiler and operating system are you using?

  • Compiler: GCC 10.3.0 (also fails with GCC 11.1.0)
  • Operating system: Ubuntu 20.04

Which version of the library did you use?

  • latest release version 3.10.0

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below

(I am waiting for the test suite to run; I have a slow network and it takes a while to download.)

@nlohmann
Copy link
Owner

I can reproduce the behavior, though I am not sure what you expect when you pass a vector of json objects to the parse function?

@slhck
Copy link
Author

slhck commented Aug 24, 2021

I am sure this worked at some point, weird. (Or the tests never ran properly.)

I expected to be able to have it simply convert the vector of JSON objects into a native JSON array object.

If that was possible, it would be easier to convert the newline-delimited JSON-formatted string into a proper JSON object without having to resort to manually building a complete string. Right now I work around this by creating a stringstream, adding "[" in the beginning, etc., then parsing the final result with json::parse().

Perhaps this is an XY problem, and in reality I need a better way to construct the final JSON object on the go.

@nlohmann
Copy link
Owner

I think the reason for the behavior is that the parser wants to treat a vector of multi-byte elements as a wide string. This may be weird, but was not changed in the last releases.

If you want to combine multiple json values in a JSON array, do this:

  json foo_vec;
  foo_vec.push_back(json::parse("{\"foo\": \"bar\"}"));
  foo_vec.push_back(json::parse("{\"baz\": \"baz\"}"));

Alternatively, you could do this:

  std::vector<json> foo_vec;
  foo_vec.push_back(json::parse("{\"foo\": \"bar\"}"));
  foo_vec.push_back(json::parse("{\"baz\": \"baz\"}"));
  json foo_array = foo_vec;

@slhck
Copy link
Author

slhck commented Aug 24, 2021

That would be much simpler, thank you.

@slhck slhck closed this as completed Aug 24, 2021
@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed kind: bug labels Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants