qicosmos / iguana

universal serialization engine
Apache License 2.0
1.12k stars 228 forks source link

compile error when serialize a more complicate struct to json when using clang 14.0.0-1ubuntu1 on ubuntu 22.04.1LTS #169

Open cagev opened 1 year ago

cagev commented 1 year ago

在ubuntu22.04上使用 clang 14 编译 序列化一个更复杂的结构体到json会出现编译错误, 代码直接添加到json_example.cpp里了 https://github.com/cageq/iguana/blob/master/example/json_example.cpp

编译环境 wsl ubuntu 22.04.1 lts cc --version Ubuntu clang version 14.0.0-1ubuntu1 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin c++ --version Ubuntu clang version 14.0.0-1ubuntu1 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin

同样平台切换到gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0 没有问题, 感觉代码应该没问题,怀疑存在编译器兼容性问题。

编译错误如下:

[ 11%] Built target example [ 16%] Building CXX object CMakeFiles/json_example.dir/example/json_example.cpp.o In file included from /home/arthur/work/iguana/example/json_example.cpp:1: In file included from /home/arthur/work/iguana/iguana/jsonreader.hpp:5: In file included from /home/arthur/work/iguana/iguana/reflection.hpp:23: /home/arthur/work/iguana/iguana/detail/itoa.hpp:88:28: error: implicit instantiation of undefined template 'dec::UT<0, 16>' using U = typename UT<N,2M,Ts...>::U; ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:88:28: note: in instantiation of template class 'dec::UT<0, 8, dec::MulInv<unsigned long, false, 12379400392853802749, 90>>' requested here /home/arthur/work/iguana/iguana/detail/itoa.hpp:88:28: note: in instantiation of template class 'dec::UT<0, 4, dec::MulInv<unsigned int, false, 3518437209, 45>, dec::MulInv<unsigned long, false, 12379400392853802749, 90>>' requested here /home/arthur/work/iguana/iguana/detail/itoa.hpp:88:28: note: in instantiation of template class 'dec::UT<0, 2, dec::MulInv<unsigned short, true, 41943, 22>, dec::MulInv<unsigned int, false, 3518437209, 45>, dec::MulInv<unsigned long, false, 12379400392853802749, 90>>' requested here /home/arthur/work/iguana/iguana/detail/itoa.hpp:90:21: note: in instantiation of template class 'dec::UT<0, 1, dec::MulInv<unsigned char, false, '\xcd', 11>, dec::MulInv<unsigned short, true, 41943, 22>, dec::MulInv<unsigned int, false, 3518437209, 45>, dec::MulInv<unsigned long, false, 12379400392853802749, 90>>' requested here template using MI = typename UT<N,1, ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:96:21: note: in instantiation of template type alias 'MI' requested here template using U = typename MI::type; ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:194:51: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all) if (u < pow10<U>(N)) return head(p,U<N/2>(u)); ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:256:38: note: in instantiation of function template specialization 'dec::convert<dec::Fwd>::itoa<unsigned char, 1UL>' requested here p = convert::template itoa(p,u); ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:265:39: note: in instantiation of function template specialization 'dec::convert<dec::Fwd>::itoa<char, 1UL, nullptr>' requested here return dec::convert<dec::Fwd>::itoa(i,p); ^ /home/arthur/work/iguana/iguana/json_writer.hpp:72:12: note: in instantiation of function template specialization 'itoa_fwd' requested here auto p = itoa_fwd(value, temp); ^ /home/arthur/work/iguana/iguana/json_writer.hpp:262:16: note: in instantiation of function template specialization 'iguana::render_json_value<std::basic_string, char>' requested here render_json_value(s, t.v); ^ /home/arthur/work/iguana/example/json_example.cpp:213:11: note: in instantiation of function template specialization 'iguana::to_json<std::basic_string, FieldInfo &>' requested here iguana::tojson(fieldInfo, ss); ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:85:41: note: template is declared here template<int, int, class...> struct UT; ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:96:21: error: type 'MI<0>' (aka 'int') cannot be used prior to '::' because it has no members template using U = typename MI::type; ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:102:9: note: in instantiation of template type alias 'U' requested here U<N/2> r; // remainder with at most N decimal digits ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:195:23: note: in instantiation of template class 'dec::QR<1>' requested here QR x = split(u); ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:256:38: note: in instantiation of function template specialization 'dec::convert<dec::Fwd>::itoa<unsigned char, 1UL>' requested here p = convert::template itoa(p,u); ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:265:39: note: in instantiation of function template specialization 'dec::convert<dec::Fwd>::itoa<char, 1UL, nullptr>' requested here return dec::convert<dec::Fwd>::itoa(i,p); ^ /home/arthur/work/iguana/iguana/json_writer.hpp:72:12: note: in instantiation of function template specialization 'itoa_fwd' requested here auto p = itoa_fwd(value, temp); ^ /home/arthur/work/iguana/iguana/json_writer.hpp:262:16: note: in instantiation of function template specialization 'iguana::render_json_value<std::basic_string, char>' requested here render_json_value(s, t.v); ^ /home/arthur/work/iguana/example/json_example.cpp:213:11: note: in instantiation of function template specialization 'iguana::to_json<std::basic_string, FieldInfo &>' requested here iguana::to_json(fieldInfo, ss); ^ In file included from /home/arthur/work/iguana/example/json_example.cpp:1: In file included from /home/arthur/work/iguana/iguana/json_reader.hpp:5: In file included from /home/arthur/work/iguana/iguana/reflection.hpp:23: /home/arthur/work/iguana/iguana/detail/itoa.hpp:96:21: error: type 'MI<0>' (aka 'int') cannot be used prior to '::' because it has no members template using U = typename MI::type; ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:107:21: note: in instantiation of template type alias 'U' requested here return { q, U<N/2>( u - q pow10<U<N/2>>(N) ) }; ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:195:23: note: in instantiation of function template specialization 'dec::split<1UL>' requested here QR x = split(u); ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:256:38: note: in instantiation of function template specialization 'dec::convert::itoa<unsigned char, 1UL>' requested here p = convert::template itoa(p,u); ^ /home/arthur/work/iguana/iguana/detail/itoa.hpp:265:39: note: in instantiation of function template specialization 'dec::convert<dec::Fwd>::itoa<char, 1UL, nullptr>' requested here return dec::convert<dec::Fwd>::itoa(i,p); ^ /home/arthur/work/iguana/iguana/json_writer.hpp:72:12: note: in instantiation of function template specialization 'itoa_fwd' requested here auto p = itoa_fwd(value, temp); ^ /home/arthur/work/iguana/iguana/json_writer.hpp:262:16: note: in instantiation of function template specialization 'iguana::render_json_value<std::basic_string, char>' requested here render_json_value(s, t.*v); ^ /home/arthur/work/iguana/example/json_example.cpp:213:11: note: in instantiation of function template specialization 'iguana::to_json<std::basic_string, FieldInfo &>' requested here iguana::to_json(fieldInfo, ss); ^ 3 errors generated. make[2]: [CMakeFiles/json_example.dir/build.make:76: CMakeFiles/json_example.dir/example/json_example.cpp.o] Error 1 make[1]: [CMakeFiles/Makefile2:125: CMakeFiles/json_example.dir/all] Error 2 make: *** [Makefile:101: all] Error 2

bbbgan commented 1 year ago

已经在最新的pr中修复,170

qicosmos commented 1 year ago

已经合并了。