rttrorg / rttr

C++ Reflection Library
https://www.rttr.org
MIT License
3.11k stars 429 forks source link

max_sizeof_list returns incorrect value for template types #358

Open barycz opened 1 year ago

barycz commented 1 year ago

In our project we wanted to extend variant_basic_types so variants could hold larger objects (like 4 component float vectors) without heap allocations. The problem we encountered is that adding template types to the type_list does not work. I am not sure if there is a bug in the compiler or the rttr code, but using Visual Studio 2022 I observe following behaviour:

// I am using std::string_view as an example, but other types declared as templates or typedefed templates trigger the bug too
#include <string_view>
using namespace rttr;
using type_list_with_string_view = detail::type_list<std::string_view>;
// following static_assert won't compile
static_assert(detail::max_sizeof_list<type_list_with_string_view>::value == sizeof(std::string_view), "should equal");

The value that compiler produces is 1, which makes me think this might be an compiler issue. The same thing happens if you add std::string view (and others) to the variant_basic_types, suddenly the max_sizeof_list::value produces 1. Thanks!