felixguendling / cista

Cista is a simple, high-performance, zero-copy C++ serialization & reflection library.
https://cista.rocks
MIT License
1.84k stars 119 forks source link

MSVC v14.1x build error: C2296,C2297 #196

Closed nescirem closed 1 year ago

nescirem commented 1 year ago

Platform&Build Tools:

The compiler reported:

...
  Generating Code...
Done building target "ClCompile" in project "cista-test-single-header.vcxproj" -- FAILED.

Done building project "cista-test-single-header.vcxproj" -- FAILED.

Build FAILED.

cista-0.14\build\cista.h(6442): error C2296: '&&' : illegal, left operand has type 'const auto'
cista-0.14\build\cista.h(6442): error C2297: '&&' : illegal, right operand has type 'const auto'
cista-0.14\build\cista.h(6442): error C2296: '&&' : illegal, left operand has type 'const auto'
cista-0.14\build\cista.h(6442): error C2297: '&&' : illegal, right operand has type 'const auto'
...
  0 Warning(s)
  92 Error(s)
...

Older versions such as v0.9 can be compiled correctly.

felixguendling commented 1 year ago

Looks like it's this line?

std::enable_if_t<is_tuple_v<decay_t<T1>> && is_tuple_v<decay_t<T2>>, bool>`

In general, I think the line should be valid C++ code as it is. The CI build on Windows with MSVC seems to work fine.

Does it work if you change line 6395 to inline constexpr bool is_tuple_v = is_tuple<T>::value;? (just replace auto to bool)

nescirem commented 1 year ago

Replacing auto with bool fixed errors: C2296,C2297, but other error messages appeared when compiling with Visual Studio 2017 (Only part of the error message is intercepted here):

...
\cista-0.14\include\cista/serialization.h(237): error C2228: left of '.ptr_' must have class/struct/union 
\cista-0.14\include\cista/serialization.h(237): error C2672: 'cista::member_offset': no matching overloaded function found 
\cista-0.14\include\cista/serialization.h(237): error C2780: 'cista::offset_t cista::member_offset(const T *,Member T::* )': expects 2 arguments - 1 provided 
\cista-0.14\include\cista/serialization.h(49): note: see declaration of 'cista::member_offset' 
\cista-0.14\include\cista/serialization.h(237): error C2780: 'cista::offset_t cista::member_offset(const T *,const Member *)': expects 2 arguments - 1 provided 
\cista-0.14\include\cista/serialization.h(42): note: see declaration of 'cista::member_offset' 
\cista-0.14\include\cista/serialization.h(241): error C2672: 'cista::member_offset': no matching overloaded function found 
\cista-0.14\include\cista/serialization.h(241): error C2780: 'cista::offset_t cista::member_offset(const T *,Member T::* )': expects 2 arguments - 1 provided 
\cista-0.14\include\cista/serialization.h(241): error C2780: 'cista::offset_t cista::member_offset(const T *,const Member *)': expects 2 arguments - 1 provided 
...

Seems that some new std of c++17 are used, and it can no longer be compiled with vs2017?

felixguendling commented 1 year ago

Maybe you can replace the content of the cista_member_offset macro to return static_cast<::cista::offset_t>(offsetof(Type, Member));?

Seems that some new std of c++17 are used, and it can no longer be compiled with vs2017?

Yes, we're targeting specifically C++17 at the moment. I don't have VS2017 at hand to check releases for compatibility but we check with whatever is provided in GitHub Actions CI with C++17 flags set.