ttsuki/nanojson

Won't compile

mellertson opened this issue · 3 comments

Hello, thanks for sharing this project. I'm very interested to use it, but I'm running into issue when compiling 'test.cpp'. I tried using the following options, all result in compile errors:

-std=c++98
-std=c++03
-std=c++11
-std=c++14
-std=gnu++98
-std=gnu++03
-std=gnu+=11
-std=gnu++14

Here's the output from one of my attempts:
$ g++ -std=c++11 test.cpp -o test
In file included from test.cpp:10:0:
nanojson.h:453:14: error: explicit specialization in non-namespace scope ‘class nanojson::element::element_writer’
template <>
^
nanojson.h:454:82: error: template-id ‘snprintf’ in declaration of primary template
static void snprintf(char buffer, size_t bufferCount, char format, ...)
^
nanojson.h:475:12: error: field ‘result’ has incomplete type ‘nanojson::element’
element result;
^
In file included from test.cpp:10:0:
nanojson.h:73:9: note: forward declaration of ‘struct nanojson::element’
struct element
^
In file included from test.cpp:10:0:
nanojson.h: In static member function ‘static nanojson::element::string_t nanojson::element::element_writer::encode_string(const string_t&)’:
nanojson.h:438:71: warning: ISO C++ forbids converting a string constant to ‘char
’ [-Wwrite-strings]
snprintf(buf, bufsz, "\u%04X", static_cast(src[i]) & 0xFF);
^
nanojson.h: In instantiation of ‘static nanojson::element nanojson::element::from_iterator(T, T) [with T = __gnu_cxx::__normal_iterator<const char
, std::__cxx11::basic_string >]’:
nanojson.h:255:49: required from here
nanojson.h:280:40: error: invalid initialization of non-const reference of type ‘nanojson::element::from_iterator(T, T) [with T = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string >]::reader&’ from an rvalue of type ‘nanojson::element::from_iterator(T, T) [with T = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string >]::reader’
return element_reader::parse(reader(first, last));
^
nanojson.h:468:19: note: initializing argument 1 of ‘static nanojson::element nanojson::element::element_reader::parse(istream&) [with istream = nanojson::element::from_iterator(T, T) [with T = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string >]::reader]’
static element parse(istream &src)
^
nanojson.h: In instantiation of ‘static nanojson::element nanojson::element::from_iterator(T, T) [with T = const char*]’:
nanojson.h:260:73: required from here
nanojson.h:280:40: error: invalid initialization of non-const reference of type ‘nanojson::element::from_iterator(T, T) [with T = const char*]::reader&’ from an rvalue of type ‘nanojson::element::from_iterator(T, T) [with T = const char*]::reader’
return element_reader::parse(reader(first, last));
^
nanojson.h:468:19: note: initializing argument 1 of ‘static nanojson::element nanojson::element::element_reader::parse(istream&) [with istream = nanojson::element::from_iterator(T, T) [with T = const char*]::reader]’
static element parse(istream &src)

And here are my OS and compiler versions
$ uname -a
Linux lenny 4.4.0-47-generic #68-Ubuntu SMP Wed Oct 26 19:39:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

Thank you for your reporting.
I fixed up code to be compilable with g++ -std=c++11.
(I had only checked compiling with MSVC++. And now I checked with g++ 5.4.0 on x86_64 Cygwin)

Thanks so much! I'll try compiling it again on my end.