-
Notifications
You must be signed in to change notification settings - Fork 229
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
struct_pack is not compatible with vs2017 c++17 #523
Comments
Well, I forgot to check, I just remembered that there was support for c++17 some time ago. Everything was fine with struct_pack in our new project, but we wanted to use it in our old project as well had this problem, we couldn't upgrade the compiler version of our old project. |
Is there any simple fix for this, we don't need bit related operations, just use serialization and deserialization of some simple structures and stl containers like (stirng) |
Well, I think it's possible to fix the problem, I check the cpprefence and it seems that the highest version of VS2017 support almost all c++17 feature. |
could you try to remove template <typename T>
struct get_array_element {
using type = typename T::value_type;
};
template <typename T, std::size_t sz>
struct get_array_element<T[sz]> {
using type = T;
}; and instead it by: template <typename T>
struct get_array_element {
using type = remove_cvref_t<decltype(std::declval<T>()[0])>;
}; |
I have no environment of VS2017. So I no sure if it can fix all the problem. |
got errors
|
emmm. Could you try this? template <typename T, typename enable = void>
struct get_array_element {
using type = void;
};
template <typename T>
struct get_array_element<T,std::enable_if_t<array<T>>> {
using type = typename T::value_type;
};
template <typename T, std::size_t sz>
struct get_array_element<T[sz]> {
using type = T;
}; |
|
Well, fix one problem then jump aonther one. I afraid The VS2017 has a poor support for if-constexpr statment. template <typename T, typename enable = void>
struct get_varint_size {
static constexpr std::size_t size = 0;
};
template <typename T>
struct get_varint_size<T, std::enable_if_t<is_variant_v<T>>> {
static constexpr std::size_t size = std::variant_size_v<T>;
}; Then replace the code else if constexpr (id == type_id::variant_t) {
return check_if_compatible_element_exist_impl_variant<version, T, T,
ParentArgs...>(
std::make_index_sequence<std::variant_size_v<T>>{});
} with: else if constexpr (id == type_id::variant_t) {
return check_if_compatible_element_exist_impl_variant<version, T, T,
ParentArgs...>(
std::make_index_sequence<get_varint_size<T>::size>{});
} |
I afraid the poor support of if-constexpr statement could cause a lot of compile errors. If the compile error still exists, It's hard to fix all if-constexpr statement. |
here are the changes i've made 1>c:\program files\microsoft visual studio\2022\enterprise\vc\tools\msvc\14.16.27023\include\variant(390): error C2027: use of undefined type 'std::variant_size<_Ty>'
1> with
1> [
1> _Ty=MyStruct
1> ]
1>c:\program files\microsoft visual studio\2022\enterprise\vc\tools\msvc\14.16.27023\include\variant(390): note: see declaration of 'std::variant_size<_Ty>'
1> with
1> [
1> _Ty=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(591): note: see reference to variable template 'const size_t variant_size_v<MyStruct>' being compiled
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(478): note: see reference to function template instantiation 'size_t struct_pack::detail::calculate_compatible_version_size<T,>(void)' being compiled
1> with
1> [
1> T=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(488): note: see reference to function template instantiation 'auto struct_pack::detail::get_sorted_compatible_version_numbers<T>(void)' being compiled
1> with
1> [
1> T=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(496): note: see reference to function template instantiation 'auto struct_pack::detail::get_sorted_and_uniqued_compatible_version_numbers<T>(void)' being compiled
1> with
1> [
1> T=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack\unpacker.hpp(157): note: see reference to variable template 'const auto compatible_version_number<MyStruct>' being compiled
1>d:\yalantinglibs\include\ylt\struct_pack.hpp(282): note: see reference to function template instantiation 'struct_pack::errc struct_pack::detail::unpacker<struct_pack::detail::memory_reader,0>::deserialize<T,>(T &)' being compiled
1> with
1> [
1> T=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack.hpp(286): note: see reference to function template instantiation 'struct_pack::errc struct_pack::detail::unpacker<struct_pack::detail::memory_reader,0>::deserialize<T,>(T &)' being compiled
1> with
1> [
1> T=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack.hpp(403): note: see reference to function template instantiation 'struct_pack::errc struct_pack::deserialize_to<0,U,,View,void>(T &,const View &)' being compiled
1> with
1> [
1> U=MyStruct,
1> View=std::vector<char,std::allocator<char>>,
1> T=MyStruct
1> ]
1>d:\vs\source\repos\consoleapplication1\consoleapplication1\consoleapplication1.cpp(19): note: see reference to function template instantiation 'tl::expected<MyStruct,struct_pack::errc> struct_pack::deserialize<MyStruct,Buffer,void>(const View &)' being compiled
1> with
1> [
1> Buffer=std::vector<char,std::allocator<char>>,
1> View=std::vector<char,std::allocator<char>>
1> ]
1>c:\program files\microsoft visual studio\2022\enterprise\vc\tools\msvc\14.16.27023\include\variant(390): error C2065: 'value': undeclared identifier
1>c:\program files\microsoft visual studio\2022\enterprise\vc\tools\msvc\14.16.27023\include\variant(390): error C2131: expression did not evaluate to a constant
1>c:\program files\microsoft visual studio\2022\enterprise\vc\tools\msvc\14.16.27023\include\variant(390): note: a non-constant (sub-)expression was encountered
1>c:\program files\microsoft visual studio\2022\enterprise\vc\tools\msvc\14.16.27023\include\variant(390): error C2027: use of undefined type 'std::variant_size<_Ty>'
1> with
1> [
1> _Ty=unsigned int
1> ]
1>c:\program files\microsoft visual studio\2022\enterprise\vc\tools\msvc\14.16.27023\include\variant(390): note: see declaration of 'std::variant_size<_Ty>'
1> with
1> [
1> _Ty=unsigned int
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(591): note: see reference to variable template 'const size_t variant_size_v<unsigned int>' being compiled
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(516): note: see reference to function template instantiation 'size_t struct_pack::detail::calculate_compatible_version_size<unsigned int,T>(void)' being compiled
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(532): note: see reference to function template instantiation 'size_t struct_pack::detail::calculate_compatible_version_size<subArgs,T,0>(std::integer_sequence<unsigned __int64,0>)' being compiled
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(478): note: see reference to function template instantiation 'size_t struct_pack::detail::calculate_compatible_version_size<T,>(void)' being compiled
1> with
1> [
1> T=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack\util.h(83): error C2338: not allow empty input!
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(490): note: see reference to function template instantiation 'void struct_pack::detail::compile_time_unique<uint64_t,0,0>(const std::array<uint64_t,0> &,std::array<uint64_t,0> &)' being compiled
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(478): note: see reference to class template instantiation 'std::array<uint64_t,0>' being compiled
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(488): note: see reference to function template instantiation 'std::array<uint64_t,0> struct_pack::detail::get_sorted_compatible_version_numbers<T>(void)' being compiled
1> with
1> [
1> T=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(496): note: see reference to function template instantiation 'std::array<uint64_t,0> struct_pack::detail::get_sorted_and_uniqued_compatible_version_numbers<T>(void)' being compiled
1> with
1> [
1> T=MyStruct
1> ]
1>d:\yalantinglibs\include\ylt\struct_pack\type_calculate.hpp(496): error C2131: expression did not evaluate to a constant
1>d:\yalantinglibs\include\ylt\struct_pack\util.h(84): note: failure was caused by call of undefined function or one not declared 'constexpr'
1>d:\yalantinglibs\include\ylt\struct_pack\util.h(84): note: see usage of 'std::array<uint64_t,0>::operator []'
1>Done building project "ConsoleApplication1.vcxproj" -- FAILED. |
Use get_variant_size instead of std::variant_size_v in line 591. |
|
You can replace all |
|
I'm afraid it's no a simple problem. Maybe I will fix it later when I have time. |
Search before asking
What happened + What you expected to happen
i get an error when compiling with vs2017 c++17
Reproduction way
compiler configuration
Visual Studio 2017 (v141)
ISO C++17 Standard (/std:c++17)
first time error
maybe vs2017 c++17 didn't implement it and then I used a higher version of the bit header file and still got the error
Anything else
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: